C# HttpRuntime.Cache.Remove不';不要删除缓存
我正在尝试使用HttpRuntime.cache.remove(键)删除缓存,但没有成功。我想知道使用HttpRuntime.Cache的最佳实践是什么 关于该方法工作得非常好,并在给定项的键的情况下从缓存中删除该项。下面是一个例子:C# HttpRuntime.Cache.Remove不';不要删除缓存,c#,asp.net,httpruntime.cache,C#,Asp.net,Httpruntime.cache,我正在尝试使用HttpRuntime.cache.remove(键)删除缓存,但没有成功。我想知道使用HttpRuntime.Cache的最佳实践是什么 关于该方法工作得非常好,并在给定项的键的情况下从缓存中删除该项。下面是一个例子: class Program { static void Main() { // add an item to the cache HttpRuntime.Cache["foo"] = "bar"; C
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
}
}
你使用它的方式可能是错误的。不幸的是,您的问题中没有具体说明这一点,所以我们只能提供帮助。我曾经花了一个有趣的小时来追踪一些看起来非常相似的东西:我从缓存中删除了一些东西,但又发现了它。结果是一个移除触发器,每次都会将其放回原位。寻找类似的副作用。请提供更多详细信息,说明您到底在做什么,以及正在/没有发生什么-最好是使用一些示例代码来演示问题。此^。记住,在调用HttpRuntime.Cache.Remove()之后,委托'CacheItemRemoved'回调方法将启动,我猜您正在其中添加项。