From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/cache/delete/index.html | 150 ++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 files/zh-cn/web/api/cache/delete/index.html (limited to 'files/zh-cn/web/api/cache/delete') diff --git a/files/zh-cn/web/api/cache/delete/index.html b/files/zh-cn/web/api/cache/delete/index.html new file mode 100644 index 0000000000..f6b20ab981 --- /dev/null +++ b/files/zh-cn/web/api/cache/delete/index.html @@ -0,0 +1,150 @@ +--- +title: Cache.delete() +slug: Web/API/Cache/delete +tags: + - API + - Cache +translation_of: Web/API/Cache/delete +--- +

{{APIRef("Service Workers API")}}{{SeeCompatTable}}

+ +

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

+ +

语法

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

返回值

+ +

如果cache条目被删除,则返回resolve为true的 {{jsxref("Promise")}},否则,返回resolve为false的 {{jsxref("Promise")}}。

+ +

参数

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

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Service Workers', '#cache', 'Cache')}}{{Spec2('Service Workers')}}Initial definition.
+ +

浏览器兼容性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatChrome(40.0)}}[1]{{CompatGeckoDesktop(39)}}[2]{{CompatNo}}{{CompatOpera(24)}}{{CompatNo}}
All options supported{{CompatChrome(54.0)}}  {{CompatOpera(41)}} 
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidAndroid WebviewFirefox Mobile (Gecko)Firefox OSIE MobileOpera MobileSafari MobileChrome for Android
Basic support{{CompatNo}}{{CompatNo}}{{CompatGeckoMobile(39)}}{{CompatUnknown}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatNo}}{{CompatChrome(40.0)}}[1]
All options supported{{CompatNo}}{{CompatNo}}   {{CompatOperaMobile(41)}} {{CompatChrome(54.0)}}
+
+ +

[1] The options parameter only supports ignoreSearch, and cacheName

+ +

[2] Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR.)

+ +

参见

+ + -- cgit v1.2.3-54-g00ecf