The above is good if you know on which pages you want to clear the cache. In my instance (ASP.NET MVC), I referenced the same data from around. So when I did [save], I wanted to clear the cache site. This is what worked for me: http://aspalliance.com/668
This is done in the context of the OnActionExecuting filter. This could be easily done by overriding OnActionExecuting in BaseController or something like that.
HttpContextBase httpContext = filterContext.HttpContext; httpContext.Response.AddCacheItemDependency("Pages");
Setup:
protected void Application_Start() { HttpRuntime.Cache.Insert("Pages", DateTime.Now); }
Small setting: I have an assistant that adds “flash messages” (error messages, success messages - “This item was saved successfully”, etc.). To avoid the appearance of a flash message on each subsequent GET, I had to invalidate after recording a flash message.
Clearing Cache:
HttpRuntime.Cache.Insert("Pages", DateTime.Now);
Hope this helps.
Kevin May 20 '10 at 18:24 2010-05-20 18:24
source share