I have some static values coming from Database which needs to be persisted in the application for every user logins.(I am using ASP.Net MVC 4 application)
For that I have implemented MemoryCache (not sure if this is better than to use HttpApplicationState or System.Web.HttpContext.Current.Cache.). Appreciated if any hint I can get on this too.
//Create a custom policy as per the business need
CacheItemPolicy wkflPolicy = new CacheItemPolicy(); // I dont want to set expiration
if (wkflCache.Get("MyKey") == null)
{
// Caching all static DB values.
DataSet myDS= objEditComponent.GetDBValues();
wkflCache.Add("MyKey", myDS, wkflPolicy);
}
Its persisting for all postbacks but when I am making Ajax call from my cshtml (view) page I could not get the cache value thus have to make another DB call, after checking null condition.
Is it happening due to low memory (wondering how come every time low memory happens when I am doing a ajax call) or I am missing something here?