Cache.delete()
Cache 接口的 delete() 方法查询 request 为 key 的 Cache 条目,如果找到,则删除该 Cache 条目并返回 resolve 为 true 的 Promise 。如果没有找到,则返回 resolve 为 false 的 Promise 。
语法
js
cache.delete(request,{options}).then(function(true) {
//your cache entry has been deleted
});
返回值
参数
- request
-
请求删除的
Request。 - options 可选
-
一个对象,其属性控制删除操作中如何处理匹配缓存。可用的选项是:
ignoreSearch: 一个Boolean(en-US) 值,指定匹配进程中是否忽略url中的查询字符串。如果设置为true,http://foo.com/?value=bar中的?value=bar部分在执行匹配时会被忽略。默认为false。ignoreMethod: 一个Boolean(en-US) 值,当设置为true时,将阻止匹配操作验证{domxref("Request")}} HTTP 方法(通常只允许 GET 和 HEAD)。默认为false。ignoreVary: 一个Boolean(en-US) 值,当设置为true时,告诉匹配操作不执行VARY头匹配。In other words, if the URL matches you will get a match regardless of whether theResponseobject has aVARYheader. 默认为false。cacheName: ADOMStringthat represents a specific cache to search within. Note that this option is ignored byCache.delete().
示例
js
caches.open('v1').then(function(cache) {
cache.delete('/images/image.png').then(function(response) {
someUIUpdateFunction();
});
})
规范
| Specification |
|---|
| Service Workers # cache-delete |
浏览器兼容性
BCD tables only load in the browser