嗨,如何检查是否在缓存(System.Web.Cache)存在项目?
要检查钥匙在缓存中已经存在我shoulde能够做到以下几点:
if(Cache["MyKey"] != null)
但这却不行?如果我创建一个从Cache类的实例,我将能够获取对象是这样的:
cache.Get("MyKey") or cache["MyKey"]
但是即使我检查null是这样的:
if(cache["MyKey"] != null)
它会抛出一个NullRefException?
我在做什么错?
EDIT1:
这是我instansiate缓存
private Cache cache
{
get {
if (_cache == null)
_cache = new Cache();
return _cache; }
}
你是如何实例化Cache实例的?它状态并没有你的钥匙扔NRE,是高速缓存对象本身 – Victor 2011-02-01 20:05:41
普莱斯看到EDIT1。 – Banshee 2011-02-01 20:07:20