How to know the all the data in the cache of an Asp.Net Application

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

2 Comments

Comments have been disabled for this content.