.Net, ASP.Net, C#, VB.net, SQL Server, Xml, CSS, Design Patterns related tips, tricks, code snippets, articles, links, thoughts, etc. from Binu & Subi Thayamkery.

Binu Thayamkery is a seasoned software architect with more than 13 years of experience in developing enterprise grade connected systems using Microsoft Technologies. In his current position as a lead consultant-solution architect with Prudential Financial, he is working on architecture of next generation investment reporting framework using .net 3.5/WCF/AJAX, etc. He holds a Masters Degree in Computer Science from Colorado State University. Subi Thayamkery is an experienced software developer with more than 8 years of developing various application software systems ranging from workflow automation systems to compliance management tools. She currently works as a technology consultant for Prudential Financial where she helps develop a new system for corportate governance department. She holds an Electrical Engineering degree from New Jersey Institute of Technology.

Wednesday, March 01, 2006

Clear your web applications Cache

We all know that Cache class provides an implementation for cache for a web application in ASP.net. Cache provides fast access to frequently used data. You can add your not so frequently changed data to Cache for a speedy access. Cache has an application scope, what ever is in cache is used by all users of your web application.

Being said that, I find sometimes a need to clear my web applications cache without affecting anything. In order to do that, this is the trick I have come up with (nothing genius here :)

I created a secure page (admin login required) with a "Clear All Cache" Button,
and here is what I do in that button click!



private void ClearCache_Click(object sender, System.EventArgs e)
{
IDictionaryEnumerator CacheEnum = Cache.GetEnumerator();
string cacheKey="";
while (CacheEnum.MoveNext())
{
cacheKey = Convert.ToString(CacheEnum.Key);
Cache.Remove(cacheKey);
}

}

0 comments: