blob: f6b20ab981828447f01b517b499a630f0c56cf15 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
---
title: Cache.delete()
slug: Web/API/Cache/delete
tags:
- API
- Cache
translation_of: Web/API/Cache/delete
---
<p>{{APIRef("Service Workers API")}}{{SeeCompatTable}}</p>
<p>{{domxref("Cache")}} 接口的 <strong><code>delete()</code></strong> 方法查询request为key的 {{domxref("Cache")}} 条目,如果找到,则删除该 {{domxref("Cache")}} 条目并返回resolve为true的 {{jsxref("Promise")}} 。 如果没有找到,则返回resolve为false的 {{jsxref("Promise")}} 。</p>
<h2 id="语法">语法</h2>
<pre class="brush: js">cache.delete(request,{options}).then(function(true) {
//your cache entry has been deleted
});
</pre>
<h3 id="返回值">返回值</h3>
<p>如果cache条目被删除,则返回resolve为true的 {{jsxref("Promise")}},否则,返回resolve为false的 {{jsxref("Promise")}}。</p>
<h3 id="参数">参数</h3>
<dl>
<dt>request</dt>
<dd>请求删除的 {{domxref("Request")}}。</dd>
<dt>options {{optional_inline}}</dt>
<dd>一个对象,其属性控制删除操作中如何处理匹配缓存。可用的选项是:
<ul>
<li><code>ignoreSearch</code>: 一个 {{domxref("Boolean")}} 值,指定匹配进程中是否忽略url中的查询字符串。如果设置为true,<code>http://foo.com/?value=bar 中的 ?value=bar 部分在执行匹配时会被忽略。默认为false。</code></li>
<li><code>ignoreMethod</code>: 一个 {{domxref("Boolean")}} 值,当设置为true时,将阻止匹配操作验证{domxref("Request")}} <code>HTTP方法(通常只允许GET和HEAD)。默认为false。</code></li>
<li><code>ignoreVary</code>: 一个 {{domxref("Boolean")}} 值,当设置为true时,告诉匹配操作不执行<code>VARY头匹配。</code>In other words, if the URL matches you will get a match regardless of whether the {{domxref("Response")}} object has a <code>VARY</code> header. <code>默认为false。</code></li>
<li><code>cacheName</code>: A {{domxref("DOMString")}} that represents a specific cache to search within. Note that this option is ignored by <code>Cache.delete()</code>.</li>
</ul>
</dd>
</dl>
<h2 id="示例" style="line-height: 30px; font-size: 2.14285714285714rem;">示例</h2>
<pre class="brush: js">caches.open('v1').then(function(cache) {
cache.delete('/images/image.png').then(function(response) {
someUIUpdateFunction();
});
})</pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('Service Workers', '#cache', 'Cache')}}</td>
<td>{{Spec2('Service Workers')}}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<div>{{CompatibilityTable}}</div>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Chrome</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari (WebKit)</th>
</tr>
<tr>
<td>Basic support</td>
<td>{{CompatChrome(40.0)}}<sup>[1]</sup></td>
<td>{{CompatGeckoDesktop(39)}}<sup>[2]</sup></td>
<td>{{CompatNo}}</td>
<td>{{CompatOpera(24)}}</td>
<td>{{CompatNo}}</td>
</tr>
<tr>
<td>All options supported</td>
<td>{{CompatChrome(54.0)}}</td>
<td> </td>
<td> </td>
<td>{{CompatOpera(41)}}</td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Android Webview</th>
<th>Firefox Mobile (Gecko)</th>
<th>Firefox OS</th>
<th>IE Mobile</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
<th>Chrome for Android</th>
</tr>
<tr>
<td>Basic support</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatGeckoMobile(39)}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatChrome(40.0)}}<sup>[1]</sup></td>
</tr>
<tr>
<td>All options supported</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td> </td>
<td> </td>
<td> </td>
<td>{{CompatOperaMobile(41)}}</td>
<td> </td>
<td>{{CompatChrome(54.0)}}</td>
</tr>
</tbody>
</table>
</div>
<p>[1] The options parameter only supports <code>ignoreSearch</code>, and <code>cacheName</code>. </p>
<p>[2] Service workers (and <a href="/en-US/docs/Web/API/Push_API">Push</a>) have been disabled in the <a href="https://www.mozilla.org/en-US/firefox/organizations/">Firefox 45 & 52 Extended Support Releases</a> (ESR.)</p>
<h2 id="参见">参见</h2>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker_API/Using_Service_Workers">Using Service Workers</a></li>
<li>{{domxref("Cache")}}</li>
<li>{{domxref("WorkerGlobalScope.caches")}}</li>
</ul>
|