跳到主要内容

4.9. 利用 HTTP Caching

4.9. 利用 HTTP Caching (Leveraging HTTP Caching)

HTTP caching [HTTP-CACHING] 是提升使用 HTTP 的 application 性能和可扩展性的最重要功能之一. caching 允许 response 被存储和复用, 从而减少需要发送到 origin server 的 request 数量.

使用 HTTP 的 application SHOULD 在适当位置使用 caching. 这意味着:

  • 可以缓存的 response SHOULD 包含适当 cache directive (例如 Cache-Control).

  • 不应缓存的 response SHOULD 显式指示这一点 (例如 Cache-Control: no-store).

  • application SHOULD 使用 conditional request (例如带 If-None-MatchIf-Modified-Since), 以允许 cache 验证已存储 response.

不过, caching 会引入复杂性. application 需要仔细考虑:

  • 哪些 response 可以安全缓存, 以及缓存多久.

  • 当 resource 变化时如何处理 cache invalidation.

  • 如何确保 private 或 sensitive information 不被不适当地缓存.

  • 如何处理可能不按预期行为工作的 intermediary cache.

关于 HTTP caching 的详细信息见 [HTTP-CACHING].