Groups | Blog | Home
all groups > asp.net caching > june 2005 >

asp.net caching : HttpHandling & Caching



Francis
6/28/2005 10:12:29 PM
Hi everyone,
I have a page that is being requested from an http handler in the
web.config file. I am trying to get this to cache so it just executes
the code every half hour. I have tried programatically, but it doesn't
seem to work at all, I tried with the following simple code:

context.Response.Write( DateTime.Now );
context.Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
context.Response.Cache.SetSlidingExpiration(true);
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetValidUntilExpires(true);

Every time the page is executed, the date updates regardless. I have
tried writing the date at the bottom of this code too, just in case.

Could anyone help?
Thanks
Francis
7/1/2005 12:00:00 AM
Hi,
Thanks for your help. Sorry, I quickly entered that code here and put
60 seconds. I'll try it again with SetMaxAge() too.
Thanks for your help
Francis

[quoted text, click to view]
Joerg Jooss
7/1/2005 6:45:53 AM
[quoted text, click to view]

Two remarks:

-- This keeps your response only fresh for 60 seconds -- but you wanted
30 minutes?

-- It's better to use SetMaxAge(), as it specifies freshness in
relative time instead of absolute as SetExpires() does (unless you're
serving to HTTP 1.0 clients, which don't understand max-age).

[quoted text, click to view]

That's weird; if I put your code in a simple web form, it is cached for
60 seconds as expected. Are you sure that the client isn't the culprit?

Cheers,
--
http://www.joergjooss.de
AddThis Social Bookmark Button