--- title: Cache.matchAll() slug: Web/API/Cache/matchAll translation_of: Web/API/Cache/matchAll ---
{{APIRef("Service Workers API")}}{{SeeCompatTable}}
{{domxref("Cache")}} 接口的 matchAll() 方法返回一个 {{jsxref("Promise")}} ,其 resolve 为 {{domxref("Cache")}} 对象中所有匹配请求的数组。
cache.matchAll(request,{options}).then(function(response) {
//do something with the response array
});
一个 {{jsxref("Promise")}},resolve为 {{domxref("Cache")}} 对象中所有匹配请求的数组。
注意: {{domxref("Cache.match()")}} 基本上与Cache.matchAll() 相同,除了它 resolve 为 response[0] (即第一个匹配响应) 而不是 response (数组中所有匹配的响应)。
response 的副本。match 操作中要做的匹配设置特定控制选项。可用选项包括:
ignoreSearch: 一个 {{domxref("Boolean")}} 值用来设置匹配操作是否忽略url中的query部分。如果该参数设置为 true ,那么 http://foo.com/?value=bar 中的 ?value=bar 部分就会在匹配中被忽略. 该选项默认为 false。ignoreMethod: 一个 {{domxref("Boolean")}} 值,如果设置为 true在匹配时就不会验证 {{domxref("Request")}} 对象的http 方法 (通常只允许是 GET 或 HEAD 。) 该参数默认值为 false。ignoreVary: 一个 {{domxref("Boolean")}} 值,该值如果为 true 则匹配时不进行 VARY 部分的匹配。例如,如果一个URL匹配,此时无论{{domxref("Response")}}对象是否包含VARY头部,都会认为是成功匹配。该参数默认为 false。cacheName: 一个 {{domxref("DOMString")}} ,代表一个具体的要被搜索的缓存。注意该选项被Cache.matchAll()方法忽略。caches.open('v1').then(function(cache) {
cache.matchAll('/images/').then(function(response) {
response.forEach(function(element, index, array) {
cache.delete(element);
});
});
})
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('Service Workers', '#dom-cache-matchall', 'Cache: matchAll')}} | {{Spec2('Service Workers')}} | Initial definition. |
{{Compat("api.Cache.matchAll")}}