I would like to store an object in cache for precisely one hour and then it expires. I have tried the following code but it seems to disappear after 20mins... HttpContext.Current.Cache.Add("bloggedAPI_Blocked_" + strEmail, myobject, null, DateTime.Now.AddHours(1), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.NotRemovable, null); I need to set this from a method in my app_code folder and am wondering if its something to do with HttpContext.Current erasing the cache when the session times out? Anybody know where I am going wrong? Paul.
Further testing and it seems that this does work intermittently. Iâm guessing that maybe the asp.net application is restarting periodically which is causing the cached items to get lost. Is there a way I can tell when a specific application has restarted without having to put code in global.asx? event viewer perhaps? "Paul Hale" wrote: > I would like to store an object in cache for precisely one hour and then it > expires. I have tried the following code but it seems to disappear after > 20mins... > > HttpContext.Current.Cache.Add("bloggedAPI_Blocked_" + strEmail, myobject, > null, DateTime.Now.AddHours(1), System.Web.Caching.Cache.NoSlidingExpiration, > System.Web.Caching.CacheItemPriority.NotRemovable, null); > > I need to set this from a method in my app_code folder and am wondering if > its something to do with HttpContext.Current erasing the cache when the > session times out? > > Anybody know where I am going wrong? > Paul. >