Perhaps this question should be easy, but it is not. I read the 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 somewhere 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?
Perhaps I allowed something in the code?
Thanks.
source share