A helper library that enforces restrictions on a cache including:

This means stale requests aren't used and the cache size is kept under control.

Most developers will use this module by instantiating a new CacheExpirationPlugin and passing it to a RequestWrapper, as shown in the first example below.


Using the CacheExpirationPlugin to enforce caching rules.

// Add cache expiration plugin to `RequestWrapper`.
const requestWrapper = new workbox.runtimeCaching.RequestWrapper({
  cacheName: 'runtime-cache',
  plugins: [
    // The cache size will be capped at 10 entries.
    new workbox.cacheExpiration.Plugin({maxEntries: 10})

// Add `RequestWrapper` to a runtime cache handler.
const route = new workbox.routing.RegExpRoute({
  match: ({url}) => url.domain === '',
  handler: new workbox.runtimeCaching.StaleWhileRevalidate({requestWrapper})

To use the cache expiration as it's own module, you can call the expireEntries() method to clean up the cache.

  cacheName: 'example-cache-name'