Given a controller action that is decorated with an OutputCacheAttribute, is it possible for the action itself to interact with the properties of the OutputCacheAttribute?
This would be useful if, for example, the action were to dynamically:
- Determine the
CacheItemPriorityand have that be set before returning the ActionResult. - Determine that caching should be disabled for this particular request, and thus the
NoStoreproperty is set to true.
Yes, no? If the answer is no, then what would be my fallback for output-caching in MVC with this kind of action-based dynamic behavior?
CacheItemPriority is not part of the OutputCacheAttribute so you’ll either need to subclass OutputCacheAttribute and modify from there or roll-your-own (likely by subclassing ActionFilterAttribute).
The following article shows examples of what you are trying to do. It looks like it was written before the standard MVC OutputCacheAttribute had any parameters available on it, so the majority of the article is showing what you want or things very close to what you want.
http://blog.maartenballiauw.be/post/2008/06/26/Creating-an-ASPNET-MVC-OutputCache-ActionFilterAttribute.aspx