Search code examples
c#asp.nethttpruntime.cache

What is the expiration period of items in HttpRuntime Cache....?


What is the maximum expiration time we can set to an item in HttpRuntime Cache...?
Also what is the default expiration time..?

public static void Add(string pName, object pValue)
{
  System.Web.HttpRuntime.Cache.Add(pName, pValue, null, DateTime.Now.AddSeconds(60), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
}

In above code 4th parameter is 'absoluteExpiration'.
What is the maximum value we can provide here...?

If I provide 10-05-2014, will that item available in cache for that long period...?
(This query is related to implementation of AppFabric cache. Trying to replace Httpruntime Cache with AppFabric Cache).


Solution

  • The maximum value of AbsoluteExpiration is basically NoAbsoluteExpiration. To set this you would pass it this field:

    Cache.NoAbsoluteExpiration
    

    Other than that you can use any value you want and it will cache it as long as you tell it to. However, this of course supposes that your server doesn't get reset, you don't clear the cache of AppFabric, etc. (if you'd use HttpRuntime.Cache it would also be necesarry that your application keeps alive)