I am trying to use the Memorycache to hold some data which is read often in a web app. I am trying to avoid having any reference to the System.web libraries inside my service layer (MVP) and that is why I would like to use System.runtime.caching.
Creating and filling the cache happens without problem - I can see that the data is populated when debugging. The problem is that the data is not there when I need it. The data it stores is to be used when a person clicks a button on the browser but the cache is always null after the button click happens. I thought that the Memorycache had application level scope. Is it possible to keep the Memorycache alive so that my presenter can use the data when events are triggered from a view. Many thanks in advance :D
public MemoryCache myCache = new MemoryCache("appCache");
private const string myCacheKey = "appCache";
public List<APPOINTMENT> Cache
{
get { return myCache[myCacheKey] as List<APPOINTMENT>; }
set { myCache[myCacheKey] = value; }
}
public IEnumerable<APPOINTMENT> GetAllAppointmentsFor(string client)
{
CacheItemPolicy cachePolicy = new CacheItemPolicy();
cachePolicy.AbsoluteExpiration = DateTime.Now.AddHours(2);
myCache.Add( myCacheKey, _uOW.APPOINTMENTs.GetAllAppointmentsFor(client).ToList(), cachePolicy);
var ap = Cache as List<APPOINTMENT>;
return ap;
}
Aucun commentaire:
Enregistrer un commentaire