Interaction with OutputCacheAttribute

Given a controller action that is decorated with the OutputCacheAttribute attribute, is it possible for the action to interact directly with the OutputCacheAttribute properties?

This would be useful if, for example, the action was dynamic:

  • Define CacheItemPriority and set this before returning the ActionResult.
  • Determine that caching should be disabled for this particular request, and therefore the NoStore property NoStore set to true.

Well no? If the answer is no, then what will be my rollback to cache output in MVC with such dynamic action-based behavior?

+4
source share
1 answer

CacheItemPriority is not part of the OutputCacheAttribute attribute, so you need to either subclass OutputCacheAttribute, either modify from there or use roll-your-own (probably by subclassing ActionFilterAttribute).

The following article provides examples of what you are trying to do. It seems like it was written before the standard MVC OutputCacheAttribute had any options available on it, so most articles show 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

0
source

All Articles