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.
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();
3 thoughts on “How to Clear ASP.NET Web Cache”
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.