Flush ALL items in OutputCache in C# .net MVC
Edit
.net MVC 3 is great that it has many build-in features that you can use out of the box for your web application. For example, the build-in OutputCache you just need to add a line in your controller or action and it will cache the output for you, you can
- specify how long the cache duration
- the cache location (you can select to cache on server [web server's memory] , browser , proxy and the combo of them)
- cache by parameter variation with the VaryByParam setting
e.g.
[OutputCache(Location = OutputCacheLocation.Server, Duration = 60 * 30, VaryByParam = "id,q")]
1
However, after some searches, it doesn't have a comprehensive way to flush the cache, it can only flush by the url, meaning if I need to flush everything in the cache I need to first generate ALL the url which is being cached. And with my current project, it is impossible to do so. After heavy googling, I found a smart hack to flush ALL items OutputCache in StackOverFlow, what it does is to make use of the AddCacheItemDependency from the HttpContext.Reponse Class.
In short, a cache entry is created storing a timestamp, and we make our outputcache item depend on this cache entry, so when we change the content of that cache entry to a new timestamp, all outputcache item which depend on it will be "expired".
Here is the stackoverflow link to the trick : http://stackoverflow.com/questions/11585/clearing-page-cache-in-asp-net/2876701#2876701
Flush ALL items in OutputCache in C# .net MVC
Reviewed by DF
on
1:17:00 AM
Rating: