Firefox 基于 max-age 的缓存过期行为异常
我正在开发一个虚拟地球 Web 应用程序,该应用程序提供大量地图图块,并且我正在尝试调整我的服务器发送的 http 标头,以指示浏览器 (Firefox) 缓存这些图块的到期时间。我这样做的方式是通过 Cache-Control 标头和 max-age 参数。
经过几次测试后,我意识到缓存对于低于 1799 秒(大约 30 分钟)的值不起作用。使用 firebug net panel 进行一些调试,我发现客户端和服务器时钟之间存在 30 分钟的不同步。例如,如果服务器发送此标头,指示 3600 秒过期时间:
Date Fri, 14 Oct 2011 07:46:12 GMT
Server Apache/2.2.13 (Fedora)
X-Powered-By PHP/5.2.11
Connection close
Cache-Control max-age=3600
Content-Length 47864
Content-Type image/jpeg
并且我浏览此请求的缓存内容,我会得到此信息。
Last Modified Fri Oct 14 2011 09:16:16 GMT+0100 (Hora de verano GMT)
Last Fetched Fri Oct 14 2011 09:16:16 GMT+0100 (Hora de verano GMT)
Expires Fri Oct 14 2011 09:46:11 GMT+0100 (Hora de verano GMT)
请注意,客户端时间为 GMT+1,服务器时间为 GMT,因此实际偏差约为 30 分钟。
所以,我得出的结论是,Firefox 是根据服务器日期标头计算过期时间,而不是根据客户端的响应到达日期,对吗?如果是这样,这是一个大问题,因为如果我设置 1 小时的过期时间,中国的用户将永远不会缓存,我该如何解决这个问题?提前致谢。
Im working on a virtual globe web application which serves a lot of map tiles, and i am trying to tweak the http headers that my server is sending to indicate the browser (Firefox) an expiration time for it to cache these tiles. The way im doing it is through Cache-Control header and max-age parameter.
After a few tests, I realized that caching wasnt working for values below 1799 seconds (approximately 30 minutes). Doing some debugging with firebug net panel, I found out that there is a 30 minutes desynchronization between the client and the server clocks. For example, if the server sends this header indicating a 3600 seconds expiration time:
Date Fri, 14 Oct 2011 07:46:12 GMT
Server Apache/2.2.13 (Fedora)
X-Powered-By PHP/5.2.11
Connection close
Cache-Control max-age=3600
Content-Length 47864
Content-Type image/jpeg
And i browse the cache contents for this request, i get this.
Last Modified Fri Oct 14 2011 09:16:16 GMT+0100 (Hora de verano GMT)
Last Fetched Fri Oct 14 2011 09:16:16 GMT+0100 (Hora de verano GMT)
Expires Fri Oct 14 2011 09:46:11 GMT+0100 (Hora de verano GMT)
Note that client times are GMT+1 and server are GMT, so the real skew is about 30 minutes.
So, the conclusion i get to is that Firefox is computing the expiration time from the server date header rather than the response arrival date on the client, is this right? If so this is a big issue, cause if i set a expiration of 1 hour, a user in China would never cach, how could i work this around? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
max-age 指示根据规范的响应的日期标头中的年龄。所以,是的,如果存在时钟偏差,那么用户感知的挂钟时间将会关闭。但这不应该影响中国的用户,除非他们的时钟关闭,因为当然,所有涉及的日期在比较之前都会转换为规范时区......
我确实想知道你在哪里找到不运行 ntp 的服务器!
max-age indicates age from the Date header of the response per spec. So yes, if there is clock skew then user-perceived wall-clock times will be off. But that shouldn't affect users in China, unless their clocks are off, because all the dates involved are converted to a canonical timezone before comparing, of course....
I do wonder where you found a server that's not running ntp!