123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- import { WorkboxPlugin } from 'workbox-core/types.js';
- import './_version.js';
- /**
- * This plugin can be used in the Workbox APIs to regularly enforce a
- * limit on the age and / or the number of cached requests.
- *
- * Whenever a cached request is used or updated, this plugin will look
- * at the used Cache and remove any old or extra requests.
- *
- * When using `maxAgeSeconds`, requests may be used *once* after expiring
- * because the expiration clean up will not have occurred until *after* the
- * cached request has been used. If the request has a "Date" header, then
- * a light weight expiration check is performed and the request will not be
- * used immediately.
- *
- * When using `maxEntries`, the entry least-recently requested will be removed
- * from the cache first.
- *
- * @memberof module:workbox-expiration
- */
- declare class ExpirationPlugin implements WorkboxPlugin {
- private readonly _config;
- private readonly _maxAgeSeconds?;
- private _cacheExpirations;
- /**
- * @param {Object} config
- * @param {number} [config.maxEntries] The maximum number of entries to cache.
- * Entries used the least will be removed as the maximum is reached.
- * @param {number} [config.maxAgeSeconds] The maximum age of an entry before
- * it's treated as stale and removed.
- * @param {boolean} [config.purgeOnQuotaError] Whether to opt this cache in to
- * automatic deletion if the available storage quota has been exceeded.
- */
- constructor(config?: {
- maxEntries?: number;
- maxAgeSeconds?: number;
- purgeOnQuotaError?: boolean;
- });
- /**
- * A simple helper method to return a CacheExpiration instance for a given
- * cache name.
- *
- * @param {string} cacheName
- * @return {CacheExpiration}
- *
- * @private
- */
- private _getCacheExpiration;
- /**
- * A "lifecycle" callback that will be triggered automatically by the
- * `workbox-strategies` handlers when a `Response` is about to be returned
- * from a [Cache](https://developer.mozilla.org/en-US/docs/Web/API/Cache) to
- * the handler. It allows the `Response` to be inspected for freshness and
- * prevents it from being used if the `Response`'s `Date` header value is
- * older than the configured `maxAgeSeconds`.
- *
- * @param {Object} options
- * @param {string} options.cacheName Name of the cache the response is in.
- * @param {Response} options.cachedResponse The `Response` object that's been
- * read from a cache and whose freshness should be checked.
- * @return {Response} Either the `cachedResponse`, if it's
- * fresh, or `null` if the `Response` is older than `maxAgeSeconds`.
- *
- * @private
- */
- cachedResponseWillBeUsed: WorkboxPlugin['cachedResponseWillBeUsed'];
- /**
- * @param {Response} cachedResponse
- * @return {boolean}
- *
- * @private
- */
- private _isResponseDateFresh;
- /**
- * This method will extract the data header and parse it into a useful
- * value.
- *
- * @param {Response} cachedResponse
- * @return {number|null}
- *
- * @private
- */
- private _getDateHeaderTimestamp;
- /**
- * A "lifecycle" callback that will be triggered automatically by the
- * `workbox-strategies` handlers when an entry is added to a cache.
- *
- * @param {Object} options
- * @param {string} options.cacheName Name of the cache that was updated.
- * @param {string} options.request The Request for the cached entry.
- *
- * @private
- */
- cacheDidUpdate: WorkboxPlugin['cacheDidUpdate'];
- /**
- * This is a helper method that performs two operations:
- *
- * - Deletes *all* the underlying Cache instances associated with this plugin
- * instance, by calling caches.delete() on your behalf.
- * - Deletes the metadata from IndexedDB used to keep track of expiration
- * details for each Cache instance.
- *
- * When using cache expiration, calling this method is preferable to calling
- * `caches.delete()` directly, since this will ensure that the IndexedDB
- * metadata is also cleanly removed and open IndexedDB instances are deleted.
- *
- * Note that if you're *not* using cache expiration for a given cache, calling
- * `caches.delete()` and passing in the cache's name should be sufficient.
- * There is no Workbox-specific method needed for cleanup in that case.
- */
- deleteCacheAndMetadata(): Promise<void>;
- }
- export { ExpirationPlugin };
|