In ASP.NET you can remove an item from the web cache by invoking Cache.Remove(string ID). But, what happens when, for some reason, you want to quickly clear the whole cache? There’s no Clear or RemoveAll method in System.Web.Caching.Cache object.
WORKAROUND
You can iterate over all the entries and remove them by their key (or ID), using the GetEnumerator method of the Cache class.
IDictionaryEnumerator enumerator = Cache.GetEnumerator();
{
Cache.Remove(enumerator.Key);
}
while
(enumerator.MoveNext()){
Cache.Remove(enumerator.Key);
}
thanks
Thanks for the post on how to clear the system.web.cache!
Hi, it is very useful. Another strategy is to change reference to Cache and use new one everywhere.