Ability to override the CacheProfile with RouteData

Dec 24, 2012 at 7:41 PM
Edited Dec 24, 2012 at 7:42 PM

No one else may need this, but I needed it for integration with a CMS (Umbraco). I'm generating a widgeted sidebar where the rendering is all done by the same controller action, but I wanted granular control over cache duration. Seems like it could be useful for others and wouldn't affect anyone who wasn't trying to use it.

In OnActionExecuting, all it took was ...

 if (filterContext.RouteData.Values.ContainsKey("cacheProfile") && !string.IsNullOrEmpty(filterContext.RouteData.Values["cacheProfile"].ToString()))
                CacheProfile = filterContext.RouteData.Values["cacheProfile"].ToString();