Maybe this question should be easy, but it is not. I have read Problem Using the System.Web.Caching.Cache Class in ASP.NET.
I have a singleton class:
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);
}
If, anywhere else in my code, I call the following:
CacheModel aCache = CacheModel.Instance;
aCache.SetCache("mykey", new string[2]{"Val1", "Val2"}); //this line throws null exception
Why does the second line throw a null reference exception?
Maybe I have made some mistake somewhere in the code?
Thank you.