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

Published Thursday, March 13, 2008 5:01 AM by vik20000in
Filed under: ,

Comments

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

Thursday, March 13, 2008 8:22 AM by DotNetKicks.com

You've been kicked (a good thing) - Trackback from DotNetKicks.com

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

Thursday, March 13, 2008 2:31 PM by Javier Romero

How can i read the cache Contents from other asp.net application? there are some way to know?

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

Wednesday, November 26, 2008 11:05 AM by pauljones

Good idea! My question to you is what are you gonna do when your application needs to scale and due to asp.net cache's in-process standalone nature you run into problems. The solution: Use a distributed cache. That's why Microsoft has introduced a distributed version themselves.

Cheers!

Leave a Comment

(required) 
(required) 
(optional)
(required)