Reputation: 2026
I am trying to remove the cache using the HttpRuntime.Cache.Remove(key) but invain. I wonder what are the best practices for using HttpRuntime.Cache.
Regards
Upvotes: 4
Views: 9785
Reputation: 19765
I once spent a fun-filled hour tracking down something that looked very similar: I removed something from cache only to find it back in there again. Turned out to be a remove-trigger that put it back each time. Look for side effects like that.
Upvotes: 2
Reputation: 1038940
The Remove method works perfectly fine and removes the item from the cache given its key. Here's an example:
class Program
{
static void Main()
{
// add an item to the cache
HttpRuntime.Cache["foo"] = "bar";
Console.WriteLine(HttpRuntime.Cache["foo"]); // prints bar
// remove the item from the cache
HttpRuntime.Cache.Remove("foo");
Console.WriteLine(HttpRuntime.Cache["foo"]); // prints empty string
}
}
It's probably the way you are using it that is wrong. Unfortunately this hasn't been specified in your question so that's as far as we can help.
Upvotes: 13