workbox-expiration#CacheExpiration JavaScript Examples

The following examples show how to use workbox-expiration#CacheExpiration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: sw-template.js    From Pf2eTools with MIT License 6 votes vote down vote up
resetAll = async () => {
	// Clear all caches, as these persist between service workers
	const cacheNames = await caches.keys();
	for (const cacheName of cacheNames) {
		await caches.delete(cacheName);

		// See: https://github.com/GoogleChrome/workbox/issues/2234
		const cacheExpiration = new CacheExpiration(cacheName, {maxEntries: 1});
		await cacheExpiration.delete();

		console.log(`deleted cache "${cacheName}"`);
	}

	await self.registration.unregister();

	const clients = await self.clients.matchAll();
	clients.forEach(client => client.navigate(client.url));
}