CacheExpiration.d.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import './_version.js';
  2. interface CacheExpirationConfig {
  3. maxEntries?: number;
  4. maxAgeSeconds?: number;
  5. }
  6. /**
  7. * The `CacheExpiration` class allows you define an expiration and / or
  8. * limit on the number of responses stored in a
  9. * [`Cache`](https://developer.mozilla.org/en-US/docs/Web/API/Cache).
  10. *
  11. * @memberof module:workbox-expiration
  12. */
  13. declare class CacheExpiration {
  14. private _isRunning;
  15. private _rerunRequested;
  16. private readonly _maxEntries?;
  17. private readonly _maxAgeSeconds?;
  18. private readonly _cacheName;
  19. private readonly _timestampModel;
  20. /**
  21. * To construct a new CacheExpiration instance you must provide at least
  22. * one of the `config` properties.
  23. *
  24. * @param {string} cacheName Name of the cache to apply restrictions to.
  25. * @param {Object} config
  26. * @param {number} [config.maxEntries] The maximum number of entries to cache.
  27. * Entries used the least will be removed as the maximum is reached.
  28. * @param {number} [config.maxAgeSeconds] The maximum age of an entry before
  29. * it's treated as stale and removed.
  30. */
  31. constructor(cacheName: string, config?: CacheExpirationConfig);
  32. /**
  33. * Expires entries for the given cache and given criteria.
  34. */
  35. expireEntries(): Promise<void>;
  36. /**
  37. * Update the timestamp for the given URL. This ensures the when
  38. * removing entries based on maximum entries, most recently used
  39. * is accurate or when expiring, the timestamp is up-to-date.
  40. *
  41. * @param {string} url
  42. */
  43. updateTimestamp(url: string): Promise<void>;
  44. /**
  45. * Can be used to check if a URL has expired or not before it's used.
  46. *
  47. * This requires a look up from IndexedDB, so can be slow.
  48. *
  49. * Note: This method will not remove the cached entry, call
  50. * `expireEntries()` to remove indexedDB and Cache entries.
  51. *
  52. * @param {string} url
  53. * @return {boolean}
  54. */
  55. isURLExpired(url: string): Promise<boolean>;
  56. /**
  57. * Removes the IndexedDB object store used to keep track of cache expiration
  58. * metadata.
  59. */
  60. delete(): Promise<void>;
  61. }
  62. export { CacheExpiration };