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

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