【发布时间】:2015-07-01 18:33:36
【问题描述】:
我想在我的 ASP.NET (MVC) 应用程序中将 Cache-Control 标头设置为 public。问题是之前有这样设置缓存策略的代码(我无法更改):
var response = htmlHelper.ViewContext.HttpContext.Response;
response.Cache.SetExpires(System.DateTime.UtcNow.AddDays(-1));
response.Cache.SetValidUntilExpires(false);
response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
response.Cache.SetCacheability(HttpCacheability.NoCache);
response.Cache.SetNoStore();
我以后找不到方法来覆盖这个,因为无论我如何尝试设置缓存控制,以上都会生效。例如。以下任何一项都不能对抗之前禁用的缓存:
httpContext.Response.Headers["Cache-Control"] = "public";
var cache = httpContext.Response.Cache;
cache.SetExpires(cacheItem.ValidUntilUtc);
cache.SetValidUntilExpires(true);
cache.SetRevalidation(HttpCacheRevalidation.None);
cache.SetCacheability(HttpCacheability.Public);
cache.SetMaxAge(cacheItem.ValidUntilUtc - _clock.UtcNow);
有没有办法以某种方式覆盖或重置缓存策略?
【问题讨论】:
标签: c# asp.net asp.net-mvc caching