2016-02-05 83 views
-2

我想从特定缓存中删除特定缓存值。如何从特定缓存中删除特定密钥的特定值从缓存中删除特定缓存中的特定缓存值

实施例:

Cache.Insert("TestCacheKey", "111", null, DateTime.Now.AddSeconds(60), Cache.NoSlidingExpiration, CacheItemPriority.High,null); 
Cache.Insert("TestCacheKey", "222", null, DateTime.Now.AddSeconds(60), Cache.NoSlidingExpiration, CacheItemPriority.High, null); 
Cache.Insert("TestCacheKey", "333", null, DateTime.Now.AddSeconds(60), Cache.NoSlidingExpiration, CacheItemPriority.High, null); 

所以,我在与键即TestCacheKey关联的高速缓存加了一些数据,如上所示。现在,我想从该密钥中删除一个特定的值,即“111”,即TestCacheKey。删除该特定值后,当我检索该缓存键(TestCacheKey)时,我应该只获取其余两个记录,其值为与该密钥关联的值“222”&“333”。

那么,如何才能实现从缓存中删除特定值。

+0

你可以托运缓存类的签名。 – Seabizkit

+0

你可以plz张贴你的代码 –

回答

1

Cache.Insert方法的第一个参数是Key。在你的代码中,你的键似乎是相同的,并且来自Cache对象的值可以通过键来访问。 如果我没看错,然后修改代码这样

Cache.Insert("111","TestCacheKey", null,DateTime.Now.AddSeconds(60),Cache.NoSlidingExpiration,CacheItemPriority.High,null); 
Cache.Insert("222","TestCacheKey" , null,DateTime.Now.AddSeconds(60),Cache.NoSlidingExpiration, CacheItemPriority.High, null); 
Cache.Insert("333","TestCacheKey", null, DateTime.Now.AddSeconds(60),Cache.NoSlidingExpiration, CacheItemPriority.High, null); 

对于去除

Cache.remove("111")

+0

这不是我想要的。 –

+0

如果我在缓存中有10条记录,并且我删除或添加了该缓存中的某些条件。 –

+0

单键可以只有一个值。提供更多信息 –