Cache.matchAll()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2018年4月.
Cache 接口的 matchAll() 方法返回一个 Promise ,其 resolve 为 Cache 对象中所有匹配请求的数组。
语法
js
cache.matchAll(request, { options }).then(function (response) {
//do something with the response array
});
返回值
一个 Promise,resolve 为 Cache 对象中所有匹配请求的数组。
备注:
Cache.match() 基本上与Cache.matchAll() 相同,除了它 resolve 为 response[0] (即第一个匹配响应) 而不是 response (数组中所有匹配的响应)。
参数
- request 可选
-
Cache中你尝试查找的 TheRequest. 如果忽略这一参数,你将获取到 cache 中所有response的副本。 - options 可选
-
一个选项对象,允许你为
match操作中要做的匹配设置特定控制选项。可用选项包括:ignoreSearch: 一个Boolean值用来设置匹配操作是否忽略 url 中的 query 部分。如果该参数设置为true,那么http://foo.com/?value=bar中的?value=bar部分就会在匹配中被忽略。该选项默认为false。ignoreMethod: 一个Boolean值,如果设置为true在匹配时就不会验证Request对象的http方法 (通常只允许是GET或HEAD。) 该参数默认值为false。ignoreVary: 一个Boolean值,该值如果为true则匹配时不进行VARY部分的匹配。例如,如果一个 URL 匹配,此时无论Response对象是否包含VARY头部,都会认为是成功匹配。该参数默认为false。cacheName: 一个DOMString,代表一个具体的要被搜索的缓存。注意该选项被Cache.matchAll()方法忽略。
示例
js
caches.open("v1").then(function (cache) {
cache.matchAll("/images/").then(function (response) {
response.forEach(function (element, index, array) {
cache.delete(element);
});
});
});
规范
| Specification |
|---|
| Service Workers> # cache-matchall> |
浏览器兼容性
Loading…