最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Fetch API Cache Mode - Stack Overflow

programmeradmin4浏览0评论

According to the spec, there are various cache modes for the Fetch API ("default", "no-store", "reload", "no-cache", "force-cache", and "only-if-cached").
However, it isn't clear what each mode is for, or the state of browser support.

According to the spec, there are various cache modes for the Fetch API ("default", "no-store", "reload", "no-cache", "force-cache", and "only-if-cached").
However, it isn't clear what each mode is for, or the state of browser support.

Share Improve this question edited Apr 3, 2023 at 18:16 AlexElin 1,5701 gold badge19 silver badges28 bronze badges asked Jul 24, 2015 at 2:20 Daniel HerrDaniel Herr 20.5k9 gold badges48 silver badges65 bronze badges 2
  • 3 If header list contains a header whose name is one of If-Modified-Since, If-None-Match, If-Unmodified-Since, If-Match, and If-Range, fetch will set cache mode to "no-store" if it is "default". fetch.spec.whatwg.org/#concept-request-cache-mode basically you can only turn it on and off at this point, or so it seems... – dandavis Commented Jul 24, 2015 at 2:22
  • See MDN Request.cache for what the each mode is for – AlexElin Commented Apr 2, 2023 at 20:13
Add a comment  | 

2 Answers 2

Reset to default 15

You can see the documentation of the polyfill here: https://fetch.spec.whatwg.org/

It does explain what each value means

"default" Fetch will inspect the HTTP cache on the way to the network. If there is a fresh response it will be used. If there is a stale response a conditional request will be created, and a normal request otherwise. It then updates the HTTP cache with the response. [HTTP]

"no-store" Fetch behaves as if there is no HTTP cache at all.

"reload" Fetch behaves as if there is no HTTP cache on the way to the network. Ergo, it creates a normal request and updates the HTTP cache with the response.

"no-cache" Fetch creates a conditional request if there is a response in the HTTP cache and a normal request otherwise. It then updates the HTTP cache with the response.

"force-cache" Fetch uses any response in the HTTP cache matching the request, not paying attention to staleness. If there was no response, it creates a normal request updates the HTTP cache with the response.

For those that match HTTP token names they are intended to have similar semantics. Unfortunately for now you'll have to go through the specification's algorithms to understand the meaning of most of these values. Also, at this point it's unclear how many of them will be standardized since there might be some security issues with them, so I might end up removing the API for this feature.

发布评论

评论列表(0)

  1. 暂无评论