这篇翻译不完整。请帮忙从英语翻译这篇文章

cache 作为Request 接口只读属性包含着请求的缓存模式。它控制着请求以何种方式与浏览器的  HTTP 缓存进行交互。

Syntax

var currentCacheMode = request.cache;

Value

A RequestCache value. The available values are:

  • default — 浏览器从HTTP缓存中寻找匹配的请求。
    • 如果缓存匹配上并且有效( fresh), 它将直接从缓存中返回资源。
    • 如果缓存匹配上但已经过期 ,浏览器将会使用传统( conditional request )的请求方式去访问远程服务器 。如果服务器端显示资源没有改动,它将从缓存中返回资源。否则,如果服务器显示资源变动,那么重新从服务器下载资源更新缓存。
    • 如果缓存没有匹配,浏览器将会以普通方式请求,并且更新已经下载的资源缓存。
  • no-store — The browser fetches the resource from the remote server without first looking in the cache, and will not update the cache with the downloaded resource.
  • reload — The browser fetches the resource from the remote server without first looking in the cache, but then will update the cache with the downloaded resource.
  • no-cache — The browser looks for a matching request in its HTTP cache.
    • If there is a match, fresh or stale, the browser will make a conditional request to the remote server. If the server indicates that the resource has not changed, it will be returned from the cache. Otherwise the resource will be downloaded from the server and the cache will be updated.
    • If there is no match, the browser will make a normal request, and will update the cache with the downloaded resource.
  • force-cache — The browser looks for a matching request in its HTTP cache.
    • If there is a match, fresh or stale, it will be returned from the cache.
    • If there is no match, the browser will make a normal request, and will update the cache with the downloaded resource.
  • only-if-cached — The browser looks for a matching request in its HTTP cache.
    • If there is a match, fresh or stale, if will be returned from the cache.
    • If there is no match, the browser will return an error.
    The "only-if-cached" mode can only be used if the request's mode is "same-origin". Cached redirects will be followed if the request's redirect property is "follow" and the redirects do not violate the "same-origin" mode.

Example

// Download a resource with cache busting, to bypass the cache
// completely.
fetch("some.json", {cache: "no-store"})
  .then(function(response) { /* consume the response */ });

// Download a resource with cache busting, but update the HTTP
// cache with the downloaded resource.
fetch("some.json", {cache: "reload"})
  .then(function(response) { /* consume the response */ });

// Download a resource with cache busting when dealing with a
// properly configured server that will send the correct ETag
// and Date headers and properly handle If-Modified-Since and
// If-None-Match request headers, therefore we can rely on the
// validation to guarantee a fresh response.
fetch("some.json", {cache: "no-cache"})
  .then(function(response) { /* consume the response */ });

// Download a resource with economics in mind!  Prefer a cached
// albeit stale response to conserve as much bandwidth as possible.
fetch("some.json", {cache: "force-cache"})
  .then(function(response) { /* consume the response */ });

Specifications

Specification Status Comment
Fetch
cache
Living Standard Initial definition

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support Nightly build (Yes) 48 (48) 未实现

未实现

11
only-if-cached 未实现 ? 50 (50) 未实现 未实现 未实现
Feature Android Edge Firefox Mobile (Gecko) Firefox OS (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support 未实现 (Yes) 未实现 未实现 未实现 未实现 未实现 未实现
only-if-cached 未实现 ? 未实现 未实现 未实现 未实现 未实现 未实现

See also

文档标签和贡献者

此页面的贡献者: Xarrow
最后编辑者: Xarrow,