为什么在请求中使用Cache-Control header?

Why use Cache-Control header in request?

This page on Cache-Control 指定以下内容:

Standard Cache-Control directives that can be used by the client in an HTTP request.

我认为只有服务器会发回有关客户端是否应缓存响应的信息。为什么客户端会向服务器发送缓存信息?

客户端和服务器之间可能有任意数量的中间代理进行缓存。客户端可以显式请求来自任何和所有缓存实体的显式缓存行为,例如:

  • max-age - "I don't want a response older than X"
  • no-cache - "I want a fresh response"
  • no-transform - "I don't want it unless it's the original"
  • only-if-cached - "Don't bother the origin server if you don't have it already"

与所有请求一样,服务器在是否接受请求方面有一定的回旋余地。仅仅因为客户端坚持未缓存的响应并不意味着它一定会得到它。