为什么缓存控制:max-age不起作用? [英] why cache-control:max-age don't work?

查看:2269
本文介绍了为什么缓存控制:max-age不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用http标头,我想在缓存控制字段上运行测试,所以我构建了一个只有一个默认页面的asp.net网站。在这个页面我正在测试 缓存控制字段,其中包含以下Page_Load中的代码:

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());

我认为每次刷新页面时都会给我相同的数字因为页面被缓存当它收到Cache-Control:max-age = 3600标题时,在浏览器本地,但令我惊讶的是,每当我按下刷新按钮(不是ctrl + f5)时,它给我一个新的数字,就像缓存控制根本不起作用。

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.

我使用fiddler捕获请求/响应信息,并看到有一个Cache-Control:max-age = 0 在请求标头中,响应头中的Cache-Control:max-age = 3600。似乎Cache-Control:max-age = 0阻止了缓存,但为什么呢?我错过了什么?

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?

推荐答案

在浏览器中,F5执行条件刷新,使用条件请求命中服务器(使用仅当服务器通过HTTP / 304说明时才执行缓存文件。要查看缓存标头的效果,请将新标签打开到同一页面。如果你配置好一切,你会看到相同的值。

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.

在这里了解有关浏览器刷新的更多信息:http://blogs.msdn.com/b/ieinternals/archive/ 2010/07/08 / technical-information-about-conditional-http-requests-and-refresh-button.aspx

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

这篇关于为什么缓存控制:max-age不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆