Thursday 14 November 2013

Clear all cache in ASP.NET

Leave a Comment
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 =)

0 comments:

Post a Comment

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.