Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpRuntime.Cache.Remove doesn't remove cache

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

like image 724
code master Avatar asked Dec 07 '22 00:12

code master


1 Answers

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.

like image 61
Darin Dimitrov Avatar answered Dec 24 '22 17:12

Darin Dimitrov