| 213 | // while the SW is still running (e.g. serving another tab) and keeps references to the deleted |
| 214 | // caches. |
| 215 | export async function clearAllCaches(caches: CacheStorage): Promise<void> { |
| 216 | const cacheNames = await caches.keys(); |
| 217 | const cacheInstances = await Promise.all(cacheNames.map((name) => caches.open(name))); |
| 218 | |
| 219 | // Delete all cache instances from `CacheStorage`. |
| 220 | await Promise.all(cacheNames.map((name) => caches.delete(name))); |
| 221 | |
| 222 | // Delete all entries from each cache instance. |
| 223 | await Promise.all( |
| 224 | cacheInstances.map(async (cache) => { |
| 225 | const keys = await cache.keys(); |
| 226 | await Promise.all(keys.map((key) => cache.delete(key))); |
| 227 | }), |
| 228 | ); |
| 229 | } |