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