Last post Aug 14, 2013 08:24 AM by LittleClive
Aug 13, 2013 02:08 PM|LittleClive|LINK
I am using trying to use perf counters to monitor the HttpRuntime.Cache to see how many items are currently in the cache. This is based on:
However in Performance Monitor I see the "Cache Total Entries" briefly increase for about a second as I insert into the cache but then it goes back to zero again, i.e. it seems to show a delta not a total.
As a test I'm doing this in a button onclick handler of a brand new asp.net site:
HttpRuntime.Cache.Insert(Guid.NewGuid().ToString(), "Value 1234", null, DateTime.MaxValue, TimeSpan.FromMinutes(5), CacheItemPriority.Default, null);
If I break into the code and look at HttpRuntime.Cache.Count it appears to reflect an accurate number.
Am running Win2K8 R2 SP1, ASP.NET 4.0. Any thoughts appreciated.
Aug 14, 2013 05:04 AM|feelwang|LINK
Just as what you said, I test it and it return a accurate number.
protected void Button1_Click(object sender, EventArgs e)
int count = HttpRuntime.Cache.Count;
string key = Guid.NewGuid().ToString();
HttpRuntime.Cache.Insert(key, key, null, DateTime.MaxValue, TimeSpan.FromMinutes(5), CacheItemPriority.Default, null);
string key1 = Guid.NewGuid().ToString();
HttpRuntime.Cache.Insert(key1, key1, null, DateTime.MaxValue, TimeSpan.FromMinutes(5), CacheItemPriority.Default, null);
if (HttpRuntime.Cache[key] == null)
cacheContent = "No Cache";
cacheContent = (string)HttpRuntime.Cache[key];
Refer to :
Aug 14, 2013 08:24 AM|LittleClive|LINK
So for you, did your "Cache Total Entries" performance counter stay at 2? (assuming two entries in HttpRuntime.Cache.Count = 2) because for me that is not happening.
The HttpRuntime.Cache.Count is fine but the performance counter has gone back to zero.
The following shows the button to add to cache being clicked on (using the code from my original post) along with the HttpRuntime.Cache.Count - alongside is the performance counter that goes back to zero even though there are items still in the cache:
Update 1: I cannot repro this on Windows 8, seems to work as expected there so it's either my machine or it's Win2K8 R2 SP1 specific.
Update 2: this issue does reproduce on a colleague's machine who is also using Win2K8 R2 SP1.
Update 3: Somehow this issue has resolved itself(?), perhaps one of the changes I did only took affect after a reboot but my machine is now reporting cache entries more reasonably (doesn't quite match the count but doesn't fall back down).
My colleague still has the issue so it would still be good to find out what needs to be done to resolve it. I did run