Cache-Control
约 2 分钟阅读
- MDN Cache-ControlLinkdeveloper.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-ControlMDN Cache-Control · https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching笔记:Cache-Control
- developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching
- support.cloudflare.com/hc/en-us/articles/115003206852-Understanding-Origin-Cache-Control
- max-age=0 vs no-cache
- If-None-Match
W/weak validator- GET, HEAD
- 值为 etag, 存在则返回 304 Not Modified
- 修改操作, 412 Precondition Failed
If-None-Match: "<etag>"[, "<etag>"]
- 参考
- [RFC 9111] HTTP Caching, STD 98
- 替代 [RFC 7234] - Hypertext Transfer Protocol (HTTP/1.1): Caching
- darkweak/souinGitHubdarkweak/souin
- MIT, Go
- An HTTP cache system, RFC compliant, compatible
- jaredwray/cacheableGitHubjaredwray/cacheable
- MIT, NodeJS
- node http request
- undici http caching
- natemoo-re/ultrafetchGitHubnatemoo-re/ultrafetch
- MIT, TS
- fetch
- [RFC 9111] HTTP Caching, STD 98
- ETag + If-None-Match
- Last-Modified + If-Modified-Since
- Cache-Control + Expires
请求
Cache-Control: max-age=<seconds>
Cache-Control: max-stale[=<seconds>]
Cache-Control: min-fresh=<seconds>
Cache-Control: no-cache
Cache-Control: no-store
Cache-Control: no-transform
Cache-Control: only-if-cached响应
Cache-Control: must-revalidate
Cache-Control: no-cache
Cache-Control: no-store
Cache-Control: no-transform
Cache-Control: public
Cache-Control: private
Cache-Control: proxy-revalidate
Cache-Control: max-age=<seconds>
Cache-Control: s-maxage=<seconds>
Cache-Control: immutable
Cache-Control: stale-while-revalidate=<seconds>
Cache-Control: stale-if-error=<seconds>- private - 面向单用户 - Authorization - browser 缓存
- public - 多用户共享缓存 - proxy cache 缓存
- post-check
- pre-check
- immutable
- max-age 内避免尝试校验缓存
# 单位为秒
Cache-Control: public, max-age=3600
Expires: Thu, 01 Dec 2014 16:00:00 GMT- Cache-Control: public, max-age=86400
- static asset
- Cache-Control: no-store
- 不缓存
- Cache-Control: private, max-age=3600
- 浏览器缓存但 Proxy 不缓存
- Cache-Control: public, no-cache
- prefer revalidation when served
- Cache-Control: public, no-cache, proxy-revalidate or Cache-Control: public, s-maxage=0
- Cache assets in proxy caches but REQUIRE revalidation by the proxy when served
- Cache-Control: public, no-cache, must-revalidate
- Cache assets in proxy caches, but REQUIRE revalidation by any cache when served
- Cache-Control: public, no-transform
- Cache assets, but ensure the proxy does not modify it
- Cache-Control: public, max-age=3600, stale-if-error=60
- Cache assets with revalidation, but allow stale responses if origin server is unreachable
- Cache-Control: public, max-age=7200, s-maxage=3600
- Cache assets for different amounts of time on Cloudflare and in visitor browsers
- Cache-Control: max-age=600, stale-while-revalidate=30
- Cache an asset and serve while asset is being revalidated
- developers.cloudflare.com/cache/about/cache-controlLinkdevelopers.cloudflare.com/cache/about/cache-controlMDN Cache-Control · https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching笔记:Cache-Control
平台
- x-vercel-cache
- HIT, MISS
- x-vercel-id
- cf-cache-status
- HIT, MISS, EXPIRED, DYNAMIC, BYPASS
关联信息
反向链接、本文链接的其他页面和外部资料。
References
GitHub4 条
- darkweak/souingithub.com/darkweak/souin
- jaredwray/cacheablegithub.com/jaredwray/cacheable
- natemoo-re/ultrafetchgithub.com/natemoo-re/ultrafetch
- nodejs/undici#3562github.com/nodejs/undici/pull/3562
其他外链7 条
- developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Controldeveloper.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
- developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-None-Matchdeveloper.mozilla.org/en-US/docs/Web/HTTP/Headers/If-None-Match
- developers.cloudflare.com/cache/about/cache-controldevelopers.cloudflare.com/cache/about/cache-control
- developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-cachingdevelopers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching
- stackoverflow.com/a/1383359/1870054stackoverflow.com/a/1383359/1870054
- support.cloudflare.com/hc/en-us/articles/115003206852-Understanding-Origin-Cache-Controlsupport.cloudflare.com/hc/en-us/articles/115003206852-Understanding-Origin-Cache-Control
- undici.nodejs.orgundici.nodejs.org/