【发布时间】:2011-05-03 22:44:42
【问题描述】:
这个问题与my other question有关。
我有一个 MVC 应用程序,所有控制器操作都禁用了缓存。我通过在Application_BeginRequest 中设置缓存响应标头来做到这一点:
protected void Application_BeginRequest()
{
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();
}
我确实希望启用缓存的单个控制器操作。我用OutputCache 属性修饰了这个动作:
[OutputCache(Duration = 300, VaryByParam = "id")]
此操作现在会发生什么?是因为 OutputCache 属性而被缓存,还是因为响应头而没有被缓存?
-- 编辑--
看起来,响应标头优先。所以我的问题变成了:如何为单个控制器操作启用缓存?再次覆盖响应头?
【问题讨论】:
标签: c# .net asp.net-mvc caching outputcache