trimCache
This commit is contained in:
10
public/sw.js
10
public/sw.js
@@ -35,6 +35,16 @@ self.addEventListener("activate", function (event) {
|
||||
return self.clients.claim();
|
||||
});
|
||||
|
||||
function trimCache(cacheName, maxItems) {
|
||||
caches.open(cacheName).then((cache) => {
|
||||
return cache.keys().then((keys) => {
|
||||
if (keys.length > maxItems) {
|
||||
cache.delete(keys[0]).then(() => trimCache(cacheName, maxItems));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// self.addEventListener("fetch", function (event) {
|
||||
// event.respondWith(
|
||||
// caches.match(event.request).then((res) => {
|
||||
|
||||
Reference in New Issue
Block a user