1

While studying the caching strategies adopted by various search engine websites and Stackoverflow itself, I can't help but notice the subtle differences in the response headers:

Google Search

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

Yahoo Search

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

Stackoverflow Search

Cache-Control: private

There must be some logical explanation behind the settings adopted. Can someone care to explain the differences so that everyone of us can learn and benefit?

4

1 回答 1

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配置持久连接的设置。除非另有说明,否则所有使用 HTTP/1.1 的连接都是持久的,但是这些标头会更改实际的超时值,而不是使用浏览器的默认值(变化很大)。

于 2012-05-02T05:30:18.357 回答