delete() 方法在 缓存 interface finds the 缓存 entry whose key is the request, and if found, deletes the 缓存 entry and returns a Promise that resolves to true . If no 缓存 entry is found, it resolves to false .

句法

cache.delete(request, {options}).then(function(found) {
  // your cache entry has been deleted if found
});
					

参数

request
Request you are looking to delete. This can be a Request object or a URL.
选项 可选
An object whose properties control how matching is done in the delete 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.delete() .

返回值

a Promise that resolves to true if the cache entry is deleted, or false 否则。

范例

caches.open('v1').then(function(cache) {
  cache.delete('/images/image.png').then(function(response) {
    someUIUpdateFunction();
  });
})
					

规范

规范 状态 注释
服务工作者
The definition of 'Cache: delete' 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
delete 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

图例

完整支持

完整支持

不支持

不支持

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

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

见实现注意事项。

另请参阅

元数据

  • 最后修改: