2
服务工作者缓存是否支持缓存控制头?例如,如果高速缓存中的条目具有标头cache-control: no-store
或cache-control: max-age=60
,则match()
是否遵守这些标头?服务工作者缓存是否支持缓存控制头文件?
尽管报头cache-control: no-store
出现在响应中,但以下代码输出CACHE HIT
。 (我想同样的问题适用于max-age
。)
function warm(c) {
var req = new Request("/foo.txt");
var res = new Response("hello", {
status: 200,
statusText: "OK",
headers: new Headers({
"cache-control": "no-store",
"content-type": "text/plain"
})
});
return c.put(req, res).then(function() { return c; });
}
function lookup(c) {
return c.match(new Request("/foo.txt")).then(function (r) {
return r ? "CACHE HIT" : "CACHE MISS";
});
}
function deleteAllCaches() {
return caches.keys().then(function (cacheNames) {
return Promise.all(
cacheNames.map(function (cacheName) {
return caches.delete(cacheName);
})
);
});
}
self.addEventListener('install', function (event) {
event.waitUntil(
deleteAllCaches()
.then(caches.open.bind(caches, 'MYCACHE'))
.then(warm)
.then(lookup)
.then(console.log.bind(console))
.then(function() { return true; })
);
});