keys() 方法在 缓存 interface returns a Promise that resolves to an array of 缓存 键。

The requests are returned in the same order that they were inserted.

注意 : Requests with duplicate URLs but different headers can be returned if their responses have the VARY header set on them.

句法

cache.keys(request, {options}).then(function(keys) {
  // do something with your array of requests
});
					

参数

request 可选
Request want to return, if a specific key is desired. This can be a Request object or a URL.
选项 可选
An object whose properties control how matching is done in the keys operation. The available options are:
  • ignoreSearch : A 布尔 that specifies whether the matching process should ignore the query string in the url.  If set to true ?value=bar 部分在 http://foo.com/?value=bar would be ignored when performing a match. It defaults to false .
  • ignoreMethod : A 布尔 that, when set to true , prevents matching operations from validating the Request HTTP method (normally only GET and HEAD are allowed.) It defaults to false .
  • ignoreVary : A 布尔 that, when set to true, tells the matching operation not to perform VARY header matching.  In other words, if the URL matches you will get a match regardless of  whether the 响应 对象拥有 VARY header. It defaults to false .
  • cacheName : A DOMString that represents a specific cache to search within. Note that this option is ignored by Cache.keys() .

返回值

A Promise that resolves to an array of 缓存 键。

范例

caches.open('v1').then(function(cache) {
  cache.keys().then(function(keys) {
    keys.forEach(function(request, index, array) {
      cache.delete(request);
    });
  });
})
					

规范

规范 状态 注释
服务工作者
The definition of 'Cache: keys' in that specification.
工作草案 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
keys Chrome 43 Edge 16 Firefox 39 注意事项
39 注意事项
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE 不支持 No Opera 30 Safari 11 WebView Android 43 Chrome Android 43 Firefox Android 39 Opera Android 30 Safari iOS 11 Samsung Internet Android 4.0

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

见实现注意事项。

另请参阅

元数据

  • 最后修改: