CacheOnly.d.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { RouteHandlerObject, RouteHandlerCallbackOptions, WorkboxPlugin } from 'workbox-core/types.js';
  2. import './_version.js';
  3. interface CacheOnlyOptions {
  4. cacheName?: string;
  5. plugins?: WorkboxPlugin[];
  6. matchOptions?: CacheQueryOptions;
  7. }
  8. /**
  9. * An implementation of a
  10. * [cache-only]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#cache-only}
  11. * request strategy.
  12. *
  13. * This class is useful if you want to take advantage of any
  14. * [Workbox plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}.
  15. *
  16. * If there is no cache match, this will throw a `WorkboxError` exception.
  17. *
  18. * @memberof module:workbox-strategies
  19. */
  20. declare class CacheOnly implements RouteHandlerObject {
  21. private readonly _cacheName;
  22. private readonly _plugins;
  23. private readonly _matchOptions?;
  24. /**
  25. * @param {Object} options
  26. * @param {string} options.cacheName Cache name to store and retrieve
  27. * requests. Defaults to cache names provided by
  28. * [workbox-core]{@link module:workbox-core.cacheNames}.
  29. * @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
  30. * to use in conjunction with this caching strategy.
  31. * @param {Object} options.matchOptions [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
  32. */
  33. constructor(options?: CacheOnlyOptions);
  34. /**
  35. * This method will perform a request strategy and follows an API that
  36. * will work with the
  37. * [Workbox Router]{@link module:workbox-routing.Router}.
  38. *
  39. * @param {Object} options
  40. * @param {Request|string} options.request A request to run this strategy for.
  41. * @param {Event} [options.event] The event that triggered the request.
  42. * @return {Promise<Response>}
  43. */
  44. handle({ event, request }: RouteHandlerCallbackOptions): Promise<Response>;
  45. }
  46. export { CacheOnly };