Clearing Cache in ASP.NET

Sometimes you need to clear all the cached from the browser in ASP.NET application in order to save new entry is available in the cache.

The method you use is actually clear your cache.

public void ClearCacheItems()
{
   List<string> keys = new List<string>();
   IDictionaryEnumerator enumerator = Cache.GetEnumerator();
 
   while (enumerator.MoveNext())
     keys.Add(enumerator.Key.ToString());
 
   for (int i = 0; i < keys.Count; i++)
      Cache.Remove(keys[i]);
}
 

Next Recommended Reading Clear textboxes values in asp.net