Friday, April 20, 2012

MemoryCache always returns "null" after first expiration

I have the following problem, I have this kind of cache management:



public class CacheManager : ICacheManager {

private readonly ObjectCache cache;

public CacheManager() {
this.cache = MemoryCache.Default;
}

public void AddItem(string key, object itemToCache, double duration) {
var end = DateTime.Now.AddSeconds(duration);
this.cache.Add(key, itemToCache, end);
}

public T Get<T>(string key) where T : class {
try {
return (T)this.cache[key];
}
catch (Exception ex) {
return null;
}
}

public void Remove(string key) {
this.cache.Remove(key);
}
}


is quite simple.



edit



Problem: When the cache for any key expires, all the following calls to get any object in cache return "null". I check the keys and are always correct.



The problem occurs only in the client's server in my PC and my server works perfectly.



thanks.





No comments:

Post a Comment