April 17th, 2011

ASP.Net clear current cache

Uncategorized, by Moby.

Via: http://www.aspdotnetfaq.com/Faq/How-to-clear-your-ASP-NET-applications-Cache.aspx

    public void ClearApplicationCache()

    {

        List<string> keys = new List<string>();

 

        // retrieve application Cache enumerator

        IDictionaryEnumerator enumerator = Cache.GetEnumerator();

 

        // copy all keys that currently exist in Cache

        while (enumerator.MoveNext())

        {

            keys.Add(enumerator.Key.ToString());

        }

 

        // delete every key from cache

        for (int i = 0; i < keys.Count; i++)

        {

            Cache.Remove(keys[i]);

        }

    }

Back Top

Responses to “ASP.Net clear current cache”

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Back Top