This question is related to my other question.
I have an MVC application with caching disabled for all controller actions. I do this by setting cache response headers in 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();
}
There is single controller action for which I do want caching enabled. I have decorated this action with the OutputCache
attribute:
[OutputCache(Duration = 300, VaryByParam = "id")]
What happens now for this action? Does it get cached because of the OutputCache attribute, or is it not cached because of the response headers?
-- EDIT --
As it seems, the response headers take preference. So my question becomes: how can I enable cache for single controller actions? Overwrite the response headers again?