0

In many actions from the MVC application we are building up, we use OutputCache as follows:

[OutputCache(Duration = 3600, VaryByCustom = "language")]
public ActionResult SomeAction()
{
   //Action..
}

So, I want to have an action where I can flush manually all these caches:

  public ActionResult RefrescarCache()
        {
            var keys = HttpContext.Cache.Cast<DictionaryEntry>().ToList();

            keys.ForEach(k => HttpContext.Cache.Remove(k.Key.ToString()));
            ViewBag.operationResult= "The cache was flushed succesfully!";

            return View();
        }

The thing, that it seems to not work. I will aprecciate any idea or advice you have!

itsmatt
  • 31,265
  • 10
  • 100
  • 164
Pato
  • 679
  • 8
  • 24

3 Answers3

2

We've had the same problem and the only solution which was working was with:

HttpResponse.RemoveOutputCacheItem(url)

like Giedrius already mentioned.

Dirk von Grünigen
  • 322
  • 1
  • 3
  • 9
1

You should look here: http://msdn.microsoft.com/en-us/library/system.web.httpresponse.removeoutputcacheitem.aspx

Giedrius
  • 8,430
  • 6
  • 50
  • 91
0

Since everyone is asking for a way to clear the all the url´s...

I can think of two ways:

1- painfull but easy, maintain an array of virtual paths to be clean.

foreach(string path in myArray){HttpResponse.RemoveOutputCacheItem(path); }

2- Uses reflection to get everything, example here: list OutputCache entry

I think this is dificult because it´s not ASP.NET caching the pages, but IIS (7+) kernel cache.

Community
  • 1
  • 1
repeatdomiau
  • 791
  • 6
  • 13