Is there a method or something to force the expiration of all of the entries in the Cache collection of the HttpContext?
+5
A:
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);
Tejs
2010-05-21 18:01:15
Yup, this should work. I've used this approach before.
Pandincus
2010-05-21 18:28:16
Why use a Dictionary to hold the cache items? You only need to hold the keys; it would seem a List<string> would take care of it.
Jesse C. Slicer
2010-05-21 19:09:18
Good point. I was just thinking that I needed to keep that data around because you wouldn't be able to remove during a foreach on the enumerator.
Tejs
2010-05-21 19:19:39
+1 - Nice, deleted my answer and will use this from now on.
Kyle Rozendo
2010-05-27 13:16:56