Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, June 16, 2009 5:13 PM
How do I set the timelimit for a cache before it expires.
Currently my cache is handled by using HttpContext.Current.Cache[<keyname>] = object;
Using this method I cant see to add a time limit of expiration. How do I do this?
Previously I had used HttpContext.Current.Cache.Insert(<keyname>, object, null, DateTime.Now.AddMinutes(30), TimeSpan.Zero);
but that never worked, my object never got cached. I am using asp.net 2.0
Thanks
All replies (3)
Tuesday, June 16, 2009 11:43 PM ✅Answered
try using Cache.Add(<keyname>, object, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 30, 0), System.Web.Caching.CacheItemPriority.Default, null);
NoAbsoluteExpiration and TimeSpan attributes tell how and when the Cache should expire.
You can also use SlidingExpiration instead of Absolute.
Tuesday, June 16, 2009 11:54 PM ✅Answered
Try this:
Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
Refer below article:
http://msdn.microsoft.com/en-us/kb/kb00323290.aspx
Wednesday, June 17, 2009 12:00 AM ✅Answered
use this
Response.Cache.SetExpires(DateTime.Now.AddMinutes(60));