简体   繁体   中英

Fetch API Cache Mode

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM