|
| Clearing the Cache Programmatically |
|
|
|
|
| Messages |
|
Related Types |
This message was discovered on microsoft.public.dotnet.framework.aspnet.caching.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
| Frank Buchan |
Hello, and thanks ahead of time for any wisdom you can offer.
I have a very large web application that is working fine, and I use the Cache object to selectively cache contents of pick lists (derived from a database) and refresh those cache items (Remove them) whenever the list changes. This is working well, and shows excellent performance on the hardware we have in place.
One problem I have run into is that at least once the Cache has gone slightly out of synch, causing the cached list to be incorrect. While we don't anticipate this happening very often (once in 3 months thus far, and then only for oddball reasons that are unlikely to repeat), I would like very much to find a way to iterate through the Cache and remove all items without having to kill the ASPNET worker process.
I know that using a For Each construct I can walk the cache and examine which controls are cached, etc., but what I have been unable to do is iterate and pick out the key names I have assigned to the Cache object. I would greatly appreciate if anyone knows either a way to clear the Cache entirely in one method call (doesn't seem to be one mentioned in the help system), or what the actual syntax in VB.NET or C# would be to iterate, and remove each item by its key (the Remove method I grasp, but its getting the valid keys that is the head scratcher). Since this is going to happen very seldom, I don't anticipate the need for speed, so much as achievement of the basic result desired.
Again, thanks for any insights.
|
|
|
| |
|
| |
| | |
| |
| Sune Pedersen |
[Original message clipped]
Hi Frank,
Here is an example, doing the iteration and removing the objects, but be aware that many other objects are stored in the cache object, im not sure if removing the objects might cause problems in your environment.
Cache("mycachekey") = "Hello Cache" Dim ie As IEnumerator ie = Cache.GetEnumerator While ie.MoveNext Dim d As System.Collections.DictionaryEntry d = CType(ie.Current, DictionaryEntry) Cache.Remove(d.Key.ToString) End While Response.Write(Cache("mycachekey").ToString)
Best Regards Witcom Sune Pedersen GSM: +45 21 91 39 46 Phone: +45 75 52 12 57 E-mail Click here to reveal e-mail address Internet http://www.witcom.dk
|
|
|
| |
|
| |
| |
| Frank Buchan |
Thanks, Sune:
Luckily, I anticipated the cache holding more than just my items and prefixed my cache items with a unique prefix. I modified the code you sent just slightly to reflect that, and it works like a charm. Now, of course, I'm almost guaranteed no one ever needs it again. :)
For anyone else who wants this same safe cache clearing mechanism, the modification was to replace the line:
Cache.Remove(d.Key.ToString)
with...
Dim checkKey as String = d.Key.ToString() If InStr(checkKey,"uniquePrefix") > 0 then Cache.Remove(checkKey) End If
As this was a performance insensitive process, this solution seems to work great...and it performs fairly well, also.
Again, much thanks.
Frank Buchan
"Sune Pedersen" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address... [Original message clipped]
|
|
|
| |
|
| |
|
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|