大网数据广告活动
Web 标准与前端开发

Cache.delete()

· 52CE 我爱测

Cache 接口的 **`delete()`** 方法查询 request 为 key 的 Cache 条目,如果找到,则删除该 Cache 条目并返回 resolve 为 true 的 Promise 。如果没有找到,则返回 resolve 为 false 的 Promise 。

Service Workers API

Cache 接口的 delete() 方法查询 request 为 key 的 Cache 条目,如果找到,则删除该 Cache 条目并返回 resolve 为 true 的 Promise 。如果没有找到,则返回 resolve 为 false 的 Promise 。

语法

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

返回值

如果 cache 条目被删除,则返回 resolve 为 true 的 Promise,否则,返回 resolve 为 false 的 Promise。

参数

  • request
    • : 请求删除的 Request。
  • options
    • : 一个对象,其属性控制删除操作中如何处理匹配缓存。可用的选项是:
      • ignoreSearch: 一个 Boolean 值,指定匹配进程中是否忽略 url 中的查询字符串。如果设置为 true,http://foo.com/?value=bar 中的 ?value=bar 部分在执行匹配时会被忽略。默认为 false。
      • ignoreMethod: 一个 Boolean 值,当设置为 true 时,将阻止匹配操作验证{domxref("Request")}} HTTP 方法(通常只允许 GET 和 HEAD)。默认为 false。
      • ignoreVary: 一个 Boolean 值,当设置为 true 时,告诉匹配操作不执行 VARY 头匹配。In other words, if the URL matches you will get a match regardless of whether the Response object has a VARY header. 默认为 false。
      • cacheName: A String that represents a specific cache to search within. Note that this option is ignored by Cache.delete().

示例

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

规范

浏览器兼容性

参见

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。