Constructor

RevisionedCacheManager

new RevisionedCacheManager(input)

Constructs a new RevisionedCacheManager to handle caching of revisioned assets only.

Parameter

input

Object

Values in input have the following properties:

Parameter

cacheName

Optional

String

The cache to be used for precaching.

cacheId

Optional

String

The cacheId is prepended to the cache name. This is useful if you have multiple projects sharing the same http://localhost origin and want unique cache names.

plugins

Optional

Array of Object

Any plugins that should be invoked by the underlying RequestWrapper.

Extends
module:workbox-precaching.BaseCacheManager

Methods

addToCacheList

addToCacheList(input)

This method will add the supplied entries to the install list and can be called multiple times.

The revisionedFiles parameter of the input should contain an array of objects or strings.

Objects in this array should have a url and revision parameter where the revision is a hash, unique to the files contents, which changes whenever the file is updated. (See our getting started guide to learn how to automate this).

Strings should be URL's that contain revisioning information i.e. /styles/main.abcd.css instead of /styles/main.css. If you supply a URL which isn't revisioned, the install() step will never update the precached asset.

Parameter

input

Object

Values in input have the following properties:

Parameter

revisionedFiles

Array of (String or Object)

This should be an array of either objects or strings.

Example

revisionedManager.addToCacheList({
  revisionedFiles: [
    '/styles/hello.1234.css',
    {
      url: '/images/logo.png',
      revision: 'abcd1234'
    }
  ]
});

cleanup

cleanup() returns Promise

This method will compare the currently cached requests's and determine which requests are no longer in the cache list and can be removed from the cache.

This should be called in a service worker's activate event to avoid removing requests that are still be used by currently open pages.

Returns

Promise Promise that resolves once the cache entries have been cleaned.

getCachedUrls

getCachedUrls() returns Array of String

Returns an array of fully qualified URL's that will be cached by this cache manager.

Inherited from
module:workbox-precaching.BaseCacheManager#getCachedUrls
Returns

An array of URLs that will be cached.

getCacheName

getCacheName() returns String

Gives access to the cache name used by this caching manager.

Inherited from
module:workbox-precaching.BaseCacheManager#getCacheName
Returns

The cache name used by this manager.

install

install() returns Promise containing Array of Object

This method will go through each asset added to the cache list and fetch and update the cache for assets which have a new revision hash.

Returns

Promise containing Array of Object The promise resolves when all the desired assets are cached and up -to-date.