CacheExpiration.d.ts 2.4 KB

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