why cache-control:max-age don't work?

一个人想着一个人 提交于 2019-12-07 14:32:52

问题


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:


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



来源:https://stackoverflow.com/questions/12926977/why-cache-controlmax-age-dont-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!