如何修改缓存值

Topics: Caching Application Block
Feb 21, 2013 at 2:57 AM
private static readonly  ICacheManager cacheMarager = CacheFactory.GetCacheManager();
cacheMarager.Add(“A”, 100, CacheItemPriority.Normal, null,new AbsoluteTime(TimeSpan.FromSeconds(5)));
假如我想把"A",修改成101,那么如何操作?
比如像以往的操作方式是cacheMarager["A"]=101;但企业库好像不可以这样操作!
Feb 21, 2013 at 3:20 AM
Edited May 1, 2013 at 9:48 PM
If you want to change the cache item "A" from 100 to 101 then just call cacheManager.Add() again with the new value:
private static readonly  ICacheManager cacheMarager = CacheFactory.GetCacheManager();
//...
cacheMarager.Add(“A”, 100, CacheItemPriority.Normal, null,new AbsoluteTime(TimeSpan.FromSeconds(5)));
cacheMarager.Add(“A”, 101, CacheItemPriority.Normal, null,new AbsoluteTime(TimeSpan.FromSeconds(5)));
bool isValueEqual = (int)cacheMarager["A"] == 101 // true
The caching block internally will modify the value (and other properties of the CacheItem) in the cache for the key "A" to the new value of 101.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Feb 21, 2013 at 7:05 AM
谢谢 thanks