了解动态生成的搜索页面的缓存策略

时间:2012-05-02 03:17:11

标签: http-headers webpage dynamically-generated http-caching

在研究各种搜索引擎网站和Stackoverflow本身采用的缓存策略时,我不禁注意到响应标题中的细微差别:

Google搜索

Cache-Control: private, max-age=0
Expires: -1

Yahoo Search

Cache-Control: private
Connection: Keep-Alive
Keep-Alive: timeout=60, max=100

Stackoverflow搜索

Cache-Control: private

所采用的设置背后必须有一些合理的解释。有人可以解释这些差异,以便我们每个人都可以学习和受益吗?

1 个答案:

答案 0 :(得分:1)

来自RFC2616 HTTP/1.1 Header Field Definitions, 14.9.1 What is Cacheable

private
   Indicates that all or part of the response message is intended for a single
   user and MUST NOT be cached by a shared cache. This allows an origin server
   to state that the specified parts of the response are intended for only one
   user and are not a valid response for requests by other users. A private
   (non-shared) cache MAY cache the response.

max-age=0表示它可以缓存最多0秒。零值意味着不应执行缓存。

当存在Expires=-1时,

max-age应该被忽略,-1是无效日期,应该被解析为过去的值(意味着已经过期)。

来自RFC2616 HTTP/1.1 Header Field Definitions, 14.21 Expires

Note: if a response includes a Cache-Control field with the max-age directive
      (see section 14.9.3), that directive overrides the Expires field

HTTP/1.1 clients and caches MUST treat other invalid date formats, especially
including the value "0", as in the past (i.e., "already expired").

Connection: Keep-AliveKeep-Alive: timeout=60, max=100配置persistent connections的设置。除非另有说明,否则使用HTTP / 1.1的所有连接都是持久的,但这些标头会更改实际的超时值,而不是使用浏览器默认值(变化很大)。