Solved

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

Posted on 2005-05-12
1,648 Views
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.
0
Question by:raudi

LVL 25

Expert Comment

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

Author Comment

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

LVL 4

Accepted Solution

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

## Featured Post

### Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be \$37.1B.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…