【发布时间】:2012-09-26 15:10:00
【问题描述】:
也许这个问题应该很容易,但事实并非如此。我读过Problem Using the System.Web.Caching.Cache Class in ASP.NET。
我有一个单例类:
private System.Web.Caching.Cache _cache;
private static CacheModel _instance = null;
private CacheModel() {
_cache = new Cache();
}
public static CacheModel Instance {
get {
return _instance ?? new CacheModel();
}
}
public void SetCache(string key, object value){
_cache.Insert(key, value);
}
如果在我的代码中的其他任何地方,我会调用以下代码:
CacheModel aCache = CacheModel.Instance;
aCache.SetCache("mykey", new string[2]{"Val1", "Val2"}); //this line throws null exception
为什么第二行会抛出空引用异常?
也许我在代码的某个地方犯了一些错误?
谢谢。
【问题讨论】:
标签: c# asp.net-mvc-3 caching data-caching