Creating a list of the data cached at a point in the asp.net Application cache

Hi,

 

We all know about the use of caching in our application. With good use of cache we can increase the performance of the application considerably since application does not have to process the stuff again and again. But if we use too much of caching in the application, it can be problem. After all the data in the cache has to be stored in the memory and most of the application have limited memory. And more so in case of shared hosting.

 

But how do you know how much amount of cache is being cached. This need to be calculated at the runtime to know the data in the cache. This can help individual understand the requirement of application and change the hardware (if required). You can also remove some caching, if you cannot increase the hardware.

 

To find all the data in the cache based on the Key we can use the following code.

 

foreach (DictionaryEntry de in this.Cache)

{

        Response.Write(de.Key);

        Response.Write(" : ");

        Response.Write(de.Value);

        Response.Write("<br><br>");       

}

 

You can also bind the data to a Gridview with two bound column for key and value. This will shows us the amount of data in the cache for individual key. This can be super handy when you application is making big use of caching data.

 

Vikram


Share this post   Email it |  digg it! |  reddit! |  bookmark it!

Feedback

Posted on 3/19/2008 12:32:35 PM

I can definitely see some uses for this. I'll give it a try but let me ask you this. When it writes out the value or the dictionary entry is it just writing the value of ToString()?

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 
Copyright © 2006 - 2008 Vikram Lakhotia