4
votes

I'm leaning http headers, and i want to run a test on the "cache-control" field,so i build a asp.net website which have only a default page.In this page i'm testing the "cache-control" field with codes in the Page_Load below:

Response.AddHeader("Cache-Control","max-age=3600");
Response.Write(new Random().Next(0,9999).ToString());

I thought it will give me the same number every time when i refresh the page cause the page is cached on local by browser when it received the "Cache-Control:max-age=3600" header,but to my surprise,it gives me a new number every time when i press the refresh button(not ctrl+f5),just like the cache-control don't work at all.

I catch the request/response information using fiddler,and see there is a "Cache-Control: max-age=0" in the request header while a "Cache-Control: max-age=3600" in the response header.It seems the "Cache-Control: max-age=0" prevents the cache,but why? Am i missing something?

1

1 Answers

10
votes

In browsers, F5 performs a "Conditional Refresh" which hits the server with a Conditional request (using the cache file only if the server says to do so via a HTTP/304). To see the effect of your caching header, instead open new tabs to the same page. You will see the same value if you configured everything right.

Learn more about browser refresh here: http://blogs.msdn.com/b/ieinternals/archive/2010/07/08/technical-information-about-conditional-http-requests-and-the-refresh-button.aspx