Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear cache in specified controller in asp mvc? [duplicate]

Possible Duplicate:
How to programmatically clear outputcache for controller action method

How to clear cache in specified controller?

I try to use several approaches:

Response.RemoveOutputCacheItem();
Response.Cache.SetExpires(DateTime.Now);

There is no any effect, it not work. :( May be exists any way to get all keys in controller cache and remove they explicitly? And in which overridden method i should perform clear cache? and how to do that?

Does any ideas?

like image 341
testCoder Avatar asked Oct 08 '12 06:10

testCoder


People also ask

How does MVC handle cache in asp net?

In ASP.NET MVC, there is an OutputCache filter attribute that you can apply and this is the same concept as output caching in web forms. The output cache enables you to cache the content returned by a controller action. Output caching basically allows you to store the output of a particular controller in the memory.

Where is output cache stored in MVC?

There is a property of the OutputCache attribute 'Location' with following possible values: Any (Default): Content is cached in three locations: the web server, any proxy servers, and the web browser. Client: Content is cached on the web browser. Server: Content is cached on the web server.


1 Answers

Have you tried

[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public ActionResult DontCacheMeIfYouCan()
{

}

If this doesn't do it for you then a custom attribute like Mark Yu suggests.

like image 103
dove Avatar answered Oct 21 '22 12:10

dove