With OutputCache Duration what is the maximum amount of seconds you can use?

Hi,

Don't want to use the .NET data caching API for just one .aspx vb page, instead using

<%@ OutputCache Duration="xxx" VaryByParam="None" %>

where "xxx" is the duration in seconds.  Just wondering, can I make it a big number of seconds like 6000 so it'll stay in cache for 100 minutes or should it be limited just a handful of minutes.  At present I'm using 780 seconds.  W2003 Server has lots of memory.

Thanks.
raudiAsked:
Who is Participating?
 
ecc204Commented:
The maximum value that you can set is not a static number.  It actually shrinks every second.  Here is the reason:

You can set the duration declaratively (using the @OutputCache directive) or programmatically.  The declarative page command will get translated into its programmatic equivalent which is as follows:

Response.Cache.SetExpires(daExpirationTime);

When you use a declarative command, you are actually saying: Response.Cache.SetExpires(DateTime.Now.AddSeconds((double)nSeconds));

The declaration for AddSeconds is public DateTime AddSeconds(double value).  But what is important is the fact that there is a maximum value for the DateTime value, and it is 12/31/9999 23:59:59.9999999.  So calculate the time left to that date in seconds and it is your number.  Note that as we go forward in time, that number shrinks.  That is so, because DateTime's maximum value is static.

So, you should be able to supply a number as big as a double.  But here is the concern: I do not know whether the people who wrote the ASP.net wrote it in a way to parse for such a large number out of your declarative statement.  To be safe I would go as high as an integer -- that is 2 to the power of 31.  If you want to do it programmatically, then use any date you wish on or before 12/31/9999 23:59:59.9999999.   That would go like this:

      Response.Cache.SetExpires(DateTime.Parse(“12/31/9999 23:59:59.9999999”));

      Or better yet

      Response.Cache.SetExpires(DateTime.MaxValue);

Lets hope there is no power outage by then. :)
0
 
nauman_ahmedCommented:
Usually this value is in seconds and will stay that long.  Visit the following URL:

http://www.c-sharpcorner.com/asp/Articles/CachingInASPDPL.asp

HTH, Nauman.
0
 
raudiAuthor Commented:
Nauman,

I know that it is in seconds when using the @ OutputCache Duration and I can crank it up 780 seconds, I just wondered if there was a limit on the number of seconds because cause I want to cache just one page for over an hour.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.