How to Monitor ASP.NET Cache

We make extensive use of the Cache in our ASP.NET projects. Some projects keep as much as 20,000 items in the Cache. For test and debug purposes, sometimes it becomes necessary to look inside the Cache and remove items from the Cache on demand.

While the ASP.NET Cache is very powerful and easy to use, it is not very flexible when it comes to monitoring. We needed the ability to view a list of all items in the Cache, Item Key, Item Type, and when the item is a Collection, show how many items are in the Collection. We also wanted to be able to remove items from the Cache as necessary by simply clicking on Delete button on the list.

Thanks to Linq, a single statement can be used to prepare a list that can be bound to a GridView control. Here is an example:

Now you can assign this cacheItems to the DataSource of a GridView. With a few lines of code, you can also implement the functionality to Delete individual items from the list. If the project keeps a large number of items in Cache you may also need to implement paging.

We include this in the Admin section of any ASP.NET Project that makes extensive use of the Cache. If this is something of a more common requirement, I will post a User Control that will encapsulate the complete functionality.

Please post a comment if you think it will help.

Posted on March 1, 2010 04:20 by Haider

Comments

March 4. 2010 08:06

Shue L

It looks like the Type property in the above projection will not hold the Data Type in case of intrinsic values.

For example, if the Data Type was a string, instead of seeing 'System.String', you will see the content of the string. Same goes for any numeric value, DateTime etc.

If it is intended that way, then I think changing the name of this Property from Type to ValueOrType would be more appropriate.

Shue L

March 5. 2010 11:20

Ken L

I could use a control that showed a paged list of Cache Items. It will come in handy in some of the projects I work on.

Please post the complete control for download when you have time.

Thanks!

Ken L

March 18. 2010 02:02

Jeremy

Yes, please post the whole user control for viewing Cache.

Jeremy

July 17. 2011 19:30

Nelly

Well explained article and no doubt Asp.net cache is very powerful and flexible but not in scalability because it is an in-proc cache. Don't you think that distributed caches like NCache, AppFabric and Memcached are better options than Asp.Net itself?

Nelly

November 15. 2011 01:33

immobilier maroc tanger

I loved as very as you volition have carried absent perquisite here. The delineate is savory, your authored palpable sharp. still, you mastery gain got an edginess through that you crave be turning in the audience. evil indubitably befall plus in the prior former plus as quite the equal almost quite continuously internal case you protect this backpack.

immobilier maroc tanger

Don't Post SPAM

If you are posting a commment just to get a link, don't waste your time!

I have a sophisticated comment moderation system in place, and your comment will not be posted.

Add comment




biuquote
  • Comment
  • Preview
Loading