0

It is said that the web servers' clocks must be identical for the Expires and Cache-Control headers to work? Why is that? Can't they be off by 1 second or a few minutes?

If the cache is supposed to be good for 1 year, then won't a time difference of a few minutes or even a few hours not matter on one or some of the web servers?

In the documentation it is said that:

note that in order for this [caching] to work, all your application servers must return the same timestamps. This means that they must have their clocks synchronized. If one of them drifts out of sync, you‘ll see different timestamps at random and the cache won‘t work. In that case the browser will request the same assets over and over again even thought they didn‘t change. You can use something like Live HTTP Headers for Firefox to verify that the cache is indeed working.

4

2 回答 2

0

如果您在所有主机上运行 ntpd(并且您确实这样做了,不是吗?),它们将非常接近。它与标头的关系较少,而与?1232285206在 URL 末尾生成的缓存控制器有关。这只是一个 Unix 纪元时间(自 1970 年 1 月 1 日 00:00:00 以来的秒数),因此对于可以缓存的内容来说,几秒钟之内应该就可以了。ntpd 通常保持四分之一秒或更短的容差。(在针对多个时间服务器的一系列ntpdate测试中,我的计算机的关闭时间从未超过 0.15 秒。)

于 2010-07-21T01:22:13.183 回答
0

请注意,这是特定于 Rails 的,并且仅适用于您有多个 Web 服务器提供数据的情况。

鉴于缓存使用时间戳存储数据,如果服务器的时间戳不同,缓存将始终在其中一个(具有“较旧”时间戳的那个)上失效,因为它总是认为文件已经最近更新,因此将请求视为缓存未命中。

于 2010-07-21T00:20:16.153 回答