I want to be able to maintain certain objects between application restarts.
To do that, I want to write specific cached items out to disk in Global.asax Application_End()
function and re-load them back on Application_Start()
.
I currently have a cache helper class, which uses the following method to return the cached value:
return HttpContext.Current.Cache[key];
Problem: during Application_End()
, HttpContext.Current
is null since there is no web request (it's an automated cleanup procedure) - therefore, I cannot access .Cache[]
to retrieve any of the items to save to disk.
Question: how can I access the cache items during Application_End()
?
If you want to get access to cache object before it will be disposed, you need to use somethink like this to add object to cache:
Import namespace System.Web.Caching to your application where you are using adding objects to cache.
And when this object is going to be disposed will be called following method: