首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏HueiFeng技术专栏

    ASP.NET Core ResponseCache进行缓存操作

    其实客户端缓存的话只需要进行设置 ResponseCache 特性就可以请看如下代码片段 [ResponseCache(Duration = 100,Location = ResponseCacheLocation.Client [ResponseCache] 参数 Duration 设置缓存的存储时间(以秒为单位)。设置“Cache-control”中的“max-age”。 Location Any 缓存在代理和客户端。 严格需要中间件的 [ResponseCache] 属性的唯一参数 VaryByQueryKeys,这与实际 HTTP 标头不对应。 有关详细信息,请参阅 响应缓存在 ASP.NET Core。 如果不使用 [ResponseCache] 属性,响应缓存可能会与 VaryByQueryKeys不同。 我们再看看如上代码效果 ? ResponseCache中间件使用的 HTTP 标头 响应头 描述 Authorization 如果标头存在,则不会缓存。

    3.6K20发布于 2020-02-27
  • 来自专栏飞鸟的专栏

    Zuul的性能优化-缓存

    { @Bean public CacheManager cacheManager() { return new ConcurrentMapCacheManager("responseCache 其中,cacheManager方法返回ConcurrentMapCacheManager实例,并指定缓存名称为"responseCache";customFilter方法返回自定义的过滤器CustomFilter ctx.getRequest(); String key = request.getRequestURI(); Cache cache = cacheManager.getCache("responseCache application/json;charset=UTF-8"); return null; } } } 在以上代码中,我们通过CacheManager获取名为"responseCache

    64530编辑于 2023-04-09
  • 来自专栏芋道源码1024

    注册中心 Eureka源码解析 —— 应用实例注册发现 (九)之岁月是把萌萌的读写锁

    #getApplicationDeltasFromMultipleRegions(…) 使用写锁,配合 ResponseCache ,即减少了写锁使用的频率,每次缓存过期才使用,又避免了前六个方法因为方案 ( 不了解 ResponseCache 的同学可以加载下 《Eureka 源码解析 —— 应用实例注册发现(六)之全量获取》「 3.2 响应缓存 ResponseCache 」 ) ---- 再解释 D 想了解极小概率发生原因的同学可以加载 《Eureka 源码解析 —— 应用实例注册发现(八)之覆盖状态》「 4.3 续租场景 」 ) ---- TODO [0029] 读写锁 笔者路上突然又想了问题,可能不是上述原因,可能和 ResponseCache 也就是说,这个读写锁是针对 ResponseCache 的读写锁。

    80700发布于 2018-07-31
  • 来自专栏Vincent-yuan

    asp.net core 系列之Response caching(1)

    简单的罗列了其他的缓存技术:In-memory caching , Distributed Cache , Cache Tag Helper , Distributed Cache Tag Helper ; 讲解了使用ResponseCache ResponseCache attribute 参加设置响应缓存头部,which clients may honor when caching responses. ResponseCache attribute 为了在response caching (响应缓存)上设置合适的头,ResponseCacheAttribute 指出了必须的参数。 下面是使用VaryByHeader属性的例子: [ResponseCache(VaryByHeader = "User-Agent", Duration = 30)] public class Cache1Model [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public class Cache2Model

    88220发布于 2019-09-10
  • 来自专栏DotNet NB && CloudNative

    《ASP.NET Core 与 RESTful API 开发实战》-- (第7章)-- 读书笔记(上)

    缓存,服务端返回资源时,能够在响应消息中包含 HTTP 缓存消息头 验证缓存资源的方式有两种: 通过响应消息头中的 Last-Modified 使用实体标签消息头 ASP.NET Core 提供的 [ResponseCache AuthorController 中为 GetAuthorAsync 方法添加该特性 [HttpGet("{authorId}", Name = nameof(GetAuthorAsync))] [ResponseCache 接着在特性中使用即可 [ResponseCache(CacheProfileName = "Default")] 当缓存的资源已经过时后,客户端需要到服务器验证资源是否有效,可以通过实体标签头验证 [ HttpGet("{authorId}", Name = nameof(GetAuthorAsync))] [ResponseCache(Duration = 60, Location = ResponseCacheLocation.Client ResponseCachingOptions 包含3个属性: SizeLimit:缓存大小 MaximumBodySize:响应正文最大值 UseCaseSensitivePaths:是否区分请求路径大小写 响应缓存中间件同样使用特性设置 [ResponseCache

    77220发布于 2021-01-13
  • 来自专栏码匠的流水账

    聊聊eureka server的response cache

    CurrentRequestVersion.get(), EurekaAccept.fromString(eurekaAccept) ); String payLoad = responseCache.get return Response.status(Status.NOT_FOUND).build(); } } 以ApplicationResource为例,可以看到这里是直接调用了responseCache.get *

    * * @author Karthik Ranganathan, Greg Kim */ public class ResponseCacheImpl implements ResponseCache

    1K30发布于 2018-09-17
  • 来自专栏Java学习录

    Eureka获取服务列表源码解析

    = null && acceptEncoding.contains(HEADER_GZIP_VALUE)) { response = Response.ok(responseCache.getGZIP returnMediaType) .build(); } else { response = Response.ok(responseCache.get = null && acceptEncoding.contains(HEADER_GZIP_VALUE)) { response = Response.ok(responseCache.getGZIP returnMediaType) .build(); } else { response = Response.ok(responseCache.get 这个hashKey最后的结果就是类似于这样的:ApplicationALL_APPSJSONV2full ResponseCacheImpl 这个对象是响应缓存的实现 当hashKey创造好之后,responseCache.getGZIP

    2.7K10发布于 2019-10-24
  • 来自专栏鸿蒙开发笔记

    HarmonyOS 开发实践 —— 基于rcp的网络请求能力

    判断用户是否有权限访问资源、处理cookie方式,调用rcp请求实现拦截器能力方案当前Api12配套版本上,rcp库中添加interceptors参数做对应的拦截器功能,核心代码//定义拦截器class ResponseCache  class ResponseCachingInterceptor implements rcp.Interceptor {  constructor(private readonly cache: ResponseCache 200;      cache.setResponse(url, resp);    });    return promise;  }} //使用rcp库拦截器能力const cache = new ResponseCache

    88610编辑于 2024-11-22
  • 来自专栏Vincent-yuan

    asp.net core 系列之Reponse caching 之 Response Caching Middleware(4)

    options.MaximumBodySize = 1024; }); 四.VaryByQueryKeys 当使用MVC/Web API控制器或者Razor Pages page models,这些ResponseCache 唯一要求中间件的ResponseCache属性是VaryByQueryKeys, VaryByQueryKeys不会回应一个真实的HTTP头。 当不使用ResponseCache属性时,response caching 可以随着VaryByQueryKeys的功能变化。

    87610发布于 2019-09-11
  • 来自专栏一枝花算不算浪漫的专栏

    【一起学源码-微服务】Nexflix Eureka 源码八:EurekaClient注册表抓取

    Client端 发送抓取全量注册表的逻辑,到了Server端查看ApplicationsResource.java中的GET方法getContainers,接着看看这部分的源码 private final ResponseCache responseCache; @GET public Response getContainers(@PathParam("version") String version, = null && acceptEncoding.contains(HEADER_GZIP_VALUE)) { response = Response.ok(responseCache.getGZIP HEADER_CONTENT_TYPE, returnMediaType) .build(); } else { response = Response.ok(responseCache.get .build(); } CurrentRequestVersion.remove(); return response; } 这里接收到Client端的请求后,会去responseCache

    61310发布于 2020-01-02
  • 来自专栏芋道源码1024

    注册中心 Eureka 源码解析 —— 应用实例注册发现(六)之全量获取

    = null && acceptEncoding.contains(HEADER_GZIP_VALUE)) { 47: response = Response.ok(responseCache.getGZIP returnMediaType) 50: .build(); 51: } else { 52: response = Response.ok(responseCache.get 第 38 至 42 行 :创建响应缓存( ResponseCache ) 的键( KEY ),在 「3.2.1 缓存键」详细解析。 3.2 响应缓存 ResponseCache com.netflix.eureka.registry.ResponseCache,响应缓存接口,接口代码如下: public interface ResponseCache 省略其它无关代码 apps.setVersion(responseCache.getVersionDelta().get()); // 唯一调用到 ResponseCache#getVersionDelta

    1.3K00发布于 2018-07-31
  • 来自专栏振兴的Android修炼手册

    Android网络之HttpUrlConnection和Socket关系解析

    CONDITIONAL_CACHE:进行网络请求如果网络请求结果无效则使用缓存 //NETWORK:返回网络请求 initResponseSource(); //请求行为记录 if (responseCache instanceof HttpResponseCache) { ((HttpResponseCache) responseCache).trackResponse(responseSource ResponseSource.CONDITIONAL_CACHE) { if (cachedResponseHeaders.validate(responseHeaders)) { if (responseCache instanceof HttpResponseCache) { ((HttpResponseCache) responseCache).trackConditionalCacheHit

    1.8K30发布于 2020-05-31
  • 来自专栏云原生权限管控

    理解Kubernetes联合鉴权的工作机制

    = nil {return w.decisionOnError, "", err}// 尝试从缓存中查找该请求if entry, ok := w.responseCache.Get(string(key webhook.DefaultShouldRetry)...r.Status = result.Status// 写缓存if shouldCache(attr) {if r.Status.Allowed {w.responseCache.Add (string(key), r.Status, w.authorizedTTL)} else {w.responseCache.Add(string(key), r.Status, w.unauthorizedTTL

    82950编辑于 2022-08-30
  • 来自专栏DotNet NB && CloudNative

    .NET8 使用缓存的几种方法,你都用过吗?

    在.NET 8中,我们可以通过控制器中的ResponseCache属性来设置HTTP缓存。 Microsoft.AspNetCore.Mvc; public class CacheController : ControllerBase { [HttpGet("/api/data")] [ResponseCache

    1.1K10编辑于 2024-11-26
  • 来自专栏DotNet NB && CloudNative

    ASP.NET 核心性能优化技巧

    ResponseCache [ResponseCache(Duration=)] publicIActionResultIndex() { returnView(); } 此示例将响应缓存 60 秒,

    65910编辑于 2024-12-23
  • 来自专栏DotNet NB && CloudNative

    优化 ASP.NET Core Web API 性能方法

    [ResponseCache] [HttpGet] [ResponseCache(Duration = )] public IActionResult GetStaticData() {

    1K10编辑于 2025-01-01
  • 来自专栏码匠的流水账

    聊聊eureka的delta配置

    null && acceptEncoding.contains(HEADER_GZIP_VALUE)) { return Response.ok(responseCache.getGZIP HEADER_CONTENT_TYPE, returnMediaType) .build(); } else { return Response.ok(responseCache.get GET_ALL_CACHE_MISS_DELTA.increment(); Applications apps = new Applications(); apps.setVersion(responseCache.getVersionDelta

    1.7K10发布于 2018-09-17
  • 来自专栏技术赋能学术

    .net 温故知新【14】:Asp.Net Core WebAPI 缓存

    启动项目测试,短时间内两次调用返回的age不一样 第一次age: 第二次age: 当我在接口方法打上[ResponseCache(Duration = 10)],再次调用接口返回的信息可以看到已经有了cache-control 然后对于我们需要服务器缓存的接口打上ResponseCache属性,和设置浏览器缓存一样,还有其他参数可设置。

    1.1K20编辑于 2023-11-25
  • 来自专栏全栈程序员必看

    聊聊eureka的delta配置

    = null && acceptEncoding.contains(HEADER_GZIP_VALUE)) { return Response.ok(responseCache.getGZIP(cacheKey HEADER_GZIP_VALUE) .header(HEADER_CONTENT_TYPE, returnMediaType) .build(); } else { return Response.ok(responseCache.get GET_ALL_CACHE_MISS_DELTA.increment(); Applications apps = new Applications(); apps.setVersion(responseCache.getVersionDelta

    1.1K30编辑于 2022-06-29
  • 来自专栏DotNet NB && CloudNative

    ASP.NET Core 错误处理(Handle Errors)

    env) { app.UseExceptionHandler("/Home/Error"); } public class HomeController : Controller { [ResponseCache public class HomeController : Controller { // 处理Get请求的异常 [HttpGet("[controller]/error")] [ResponseCache HttpContext.TraceIdentifier }); } // 处理Post请求的异常 [HttpPost("[controller]/error")] [ResponseCache code={0}"); public class HomeController : Controller { [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None

    2.7K20发布于 2021-12-01
领券