Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force all ASP.NET cache to expire

Is there a method or something to force the expiration of all of the entries in the Cache collection of the HttpContext?

like image 221
ryudice Avatar asked May 21 '10 17:05

ryudice


1 Answers

Try something like this:

var enumerator = HttpRuntime.Cache.GetEnumerator();
Dictionary<string, object> cacheItems = new Dictionary<string, object>();

while (enumerator.MoveNext())
    cacheItems.Add(enumerator.Key.ToString(), enumerator.Value);

foreach (string key in cacheItems.Keys)
    HttpRuntime.Cache.Remove(key);
like image 143
Tejs Avatar answered Oct 21 '22 08:10

Tejs