当我刷新网页时,它不会从缓存加载内容。内容实际上在缓存中可用,每 4 小时过期一次



我设置了这些缓存标头

    Context.Response.Cache.SetExpires(DateTime.Now.Add(refresh));
    Context.Response.Cache.SetMaxAge(refresh);
    Context.Response.Cache.SetCacheability(HttpCacheability.Private);
    Context.Response.Cache.SetValidUntilExpires(true);
    Context.Response.ContentType = "text/html";

刷新页面时,我是否必须设置其他任何内容才能使缓存正常工作?

要以

编程方式将页面内容放置在客户端(浏览器),代理和服务器缓存中,您需要执行以下操作:

Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(15));
Response.Cache.SetMaxAge(TimeSpan.FromSeconds(15));
Response.Cache.SetValidUntilExpires(true);
Response.Cache.SetLastModified(DateTime.Now);
Response.Cache.SetOmitVaryStar(true);

最新更新