How to “invalidate” portions of ASP.NET MVC output cache?

Up vote 14 down vote favorite 12 share g+ share fb share tw.

Is there a way to programmatically invalidate portions of the ASP. NET MVC output cache? What I would like to be able to do is, if a user posts data that changes what would be returned from a cached action, be able to invalidate that cached data.

Is this even possible? Thanks, Matthew asp. Net-mvc caching link|improve this question asked Aug 17 '09 at 15:00Matthew Belk17019 18% accept rate.

– Stefanvds Feb 6 '11 at 10:00 Duplicate of: stackoverflow.com/questions/1200616/… and stackoverflow.com/questions/1167890/… – Drew Noakes Mar 15 '11 at 20:07.

One way is to use the method : HttpResponse. RemoveOutputCacheItem("/Home/About"); Another way is described here : aspalliance.com/668 I think you could implement the second method by using a method level attribute for every action that you want and just add to it the string representing the key. That's if I understood your question.

Edit: Yes the asp.net mvc OutputCache is just a wrapper . If you're using varyByParam="none" then you just invalidate "/Statistics" - that's if / are querystring values. This will invalidate all versions of the page I did a quick test and if you add varyByParam="id1" and then create multiple versions of the page - if you say invalidate invalidate "/Statistics/id1" it will invalidate just that version.

But you should do further tests.

Is the MVC OutputCache attribute just a wrapper around the usual ASP. NET output caching? So, let's say I wanted to invalidate the results for an action called "/Statistics//" I would just call HttpResponse.

RemoveOutputCacheItem("/Statistics//")? FWIW, The "VaryByParams" property of the attribute is "None. " Am I using that property correctly?

– Matthew Belk Aug 17 '09 at 21:19 @Matthew Belk: Did you use this technique in the end? Did invalidation of a cache item by param work as expected? Thanks.

– UpTheCreek Jan 22 '11 at 10:20.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions