Clear all cache in ASP.NET

The previous post was about advantage using cache in web application.Complex application must using cache to increase the performance of application. But sometime you a over heating the memory if so many information stored in cache and the cleaner(GC) need to clean up the mess. Unfortunately Garbage Collector(GC) not remove the cache, you need to do it by your self. The problem is how to get all key of the cache and then remove it.?

So the solution is you need to use the IDictionaryEnumerator to get all of the cache key.

Lets look at the method example. Feel free to try by your self.

Clear Cache Method

 public void clearCache()
        {
            IDictionaryEnumerator dictionaryEnumerators = Cache.GetEnumerator();
            if (dictionaryEnumerators.MoveNext())
            {
                Cache.Remove(dictionaryEnumerators.Key.ToString());
                clearCache();
            }
           
        }





By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

Popular posts from this blog

How to create zip file to download in JSP- Servlet

How to create DataGrid or GridView in JSP - Servlet

Pinging in ASP.NET Example