I have a global NoCache filter as shown here: https://stackoverflow.com/a/12964123/78739
This global no cache filter applies to all actions. I have a case where I need to allow caching for one particular action using OutputCacheAttribute. I was thinking in the NoCache filter I would check to see if the action that has just executed has the OutputCacheAttribute. If it does, it does NOT apply the no cache settings. So for example, my code would be:
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
public sealed class NoCacheAttribute : FilterAttribute, IResultFilter
{
public void OnResultExecuted(ResultExecutedContext filterContext)
{
if (/* action does not have OutputCacheAttribute */)
{
var cache = filterContext.HttpContext.Response.Cache;
cache.SetCacheability(HttpCacheability.NoCache);
cache.SetRevalidation(HttpCacheRevalidation.ProxyCaches);
cache.SetExpires(DateTime.Now.AddYears(-5));
cache.AppendCacheExtension("private");
cache.AppendCacheExtension("no-cache=Set-Cookie");
cache.SetProxyMaxAge(TimeSpan.Zero);
}
}
}
The problem is I don't know how to get the action and its attributes from the ResultExecutedContext variable that is passed into the OnResultExecuted method.