Constructor

CacheExpiration

new CacheExpiration(cacheName, config)

To construct a new CacheExpiration instance you must provide at least one of the config properties.

Parameter

cacheName

string

Name of the cache to apply restrictions to.

config

Object

Values in config have the following properties:

Parameter

maxEntries

Optional

number

The maximum number of entries to cache. Entries used the least will be removed as the maximum is reached.

maxAgeSeconds

Optional

number

The maximum age of an entry before it's treated as stale and removed.

Methods

expireEntries

async

expireEntries()

Expires entries for the given cache and given criteria.

isURLExpired

async

isURLExpired(url) returns boolean

Can be used to check if a URL has expired or not before it's used.

This requires a look up from IndexedDB, so can be slow.

Note: This method will not remove the cached entry, call expireEntries() to remove indexedDB and Cache entries.

Parameter

url

string

Returns

boolean 

updateTimestamp

async

updateTimestamp(url)

Update the timestamp for the given URL. This ensures the when removing entries based on maximum entries, most recently used is accurate or when expiring, the timestamp is up-to-date.

Parameter

url

string