getCacheKeyForURL.mjs 1014 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. Copyright 2019 Google LLC
  3. Use of this source code is governed by an MIT-style
  4. license that can be found in the LICENSE file or at
  5. https://opensource.org/licenses/MIT.
  6. */
  7. import {getOrCreatePrecacheController}
  8. from './getOrCreatePrecacheController.mjs';
  9. import {generateURLVariations} from './generateURLVariations.mjs';
  10. import '../_version.mjs';
  11. /**
  12. * This function will take the request URL and manipulate it based on the
  13. * configuration options.
  14. *
  15. * @param {string} url
  16. * @param {Object} options
  17. * @return {string} Returns the URL in the cache that matches the request,
  18. * if possible.
  19. *
  20. * @private
  21. */
  22. export const getCacheKeyForURL = (url, options) => {
  23. const precacheController = getOrCreatePrecacheController();
  24. const urlsToCacheKeys = precacheController.getURLsToCacheKeys();
  25. for (const possibleURL of generateURLVariations(url, options)) {
  26. const possibleCacheKey = urlsToCacheKeys.get(possibleURL);
  27. if (possibleCacheKey) {
  28. return possibleCacheKey;
  29. }
  30. }
  31. };