Demo · Vary: Cookie
public + Vary:Cookie → 每个用户 Session 独立缓存条目,CDN 命中率趋近 0
同一 URL,不同请求条件 → 不同 cache key
public + Vary:Cookie → 每个用户 Session 独立缓存条目,CDN 命中率趋近 0
同一 URL 按语言返回不同 JSON;有/无 Vary:Accept-Language 对比 CDN 是否串语言
HTTP 缓存与 Vary 的权威说明见 IETF RFC(非 MDN 原创,MDN 为导读)。
| 文档 | 内容 | 关键章节 |
|---|---|---|
| RFC 9111 | HTTP Caching — Cache-Control、fresh/stale、存储条件 |
§2 · §3 · §4.1 · §5 |
| RFC 9110 | HTTP Semantics — Vary 定义;扩大 cache key |
§12.5.5 |
| Fetch | 浏览器如何实现 HTTP 缓存(Chrome 等) | network-or-cache |
| RFC 6265 | Cookie 机制 | Cookie Demo |
| MDN | HTTP 缓存中文友好导读 | — |
RFC 9111 §2:A cache might store multiple responses for a request target … Caches differentiate these responses … using information in theVaryresponse header field.
RFC 9111 §4.1:… MUST NOT use that stored response … unless all … request header fields nominated byVary… match those fields in the original request.