[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.caching

Setting auto expiring cache from app_code folder

Paul Hale

7/23/2008 10:21:00 PM

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.

1 Answer

Paul Hale

7/24/2008 11:04:00 AM

0

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.
>