![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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.Add Seconds(60)); context.Response.Cache.SetSlidingExpiration(true); context.Response.Cache.SetCacheability(HttpCacheab ility.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. |
#3
| |||
| |||
|
|
Francis wrote: 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.Add Seconds(60)); context.Response.Cache.SetSlidingExpiration(true); context.Response.Cache.SetCacheability(HttpCacheab ility.Public); context.Response.Cache.SetValidUntilExpires(true); 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). 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. 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, |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |