cache problem

J

jack

Now here i have a doubt
the explorer maintains the cache for 300 seconds when the code is in
html code like the one which is below :-
<%@ OutputCache Duration="300" VaryByParam="none" %>


But the same code when typed in the cs file of the page does not gives
the same result.

Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
Response.Cache.SetCacheability(HttpCacheability.Private);
Im not able to guess as to you the page is not been cached for 300
seconds
 
J

Joerg Jooss

Hello Jack,
Now here i have a doubt
the explorer maintains the cache for 300 seconds when the code is in
html code like the one which is below :-
<%@ OutputCache Duration="300" VaryByParam="none" %>
But the same code when typed in the cs file of the page does not gives
the same result.

Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
Response.Cache.SetCacheability(HttpCacheability.Private);
Im not able to guess as to you the page is not been cached for 300
seconds

Well, 60 seconds and 300 seconds are not the same ;-)

Your second approach doesn't set the CacheControl: max-age header, either.
To achieve the same as the OutputCache directive in code, use

// You could also use new TimeSpan(0, 0, 300), but 5 minutes is more readable
than 300 seconds :)
TimeSpan maxAge = new TimeSpan(0, 5, 0);
Response.Cache.SetExpires(DateTime.Now.Add(maxAge));
Response.Cache.SetCacheability(HttpCacheability.Private);
Response.Cache.SetMaxAge(maxAge);

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,815
Latest member
treekmostly22

Latest Threads

Top