getCacheKeyForURL.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  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 } from './getOrCreatePrecacheController.js';
  8. import { generateURLVariations } from './generateURLVariations.js';
  9. import '../_version.js';
  10. /**
  11. * This function will take the request URL and manipulate it based on the
  12. * configuration options.
  13. *
  14. * @param {string} url
  15. * @param {Object} options
  16. * @return {string} Returns the URL in the cache that matches the request,
  17. * if possible.
  18. *
  19. * @private
  20. */
  21. export const getCacheKeyForURL = (url, options) => {
  22. const precacheController = getOrCreatePrecacheController();
  23. const urlsToCacheKeys = precacheController.getURLsToCacheKeys();
  24. for (const possibleURL of generateURLVariations(url, options)) {
  25. const possibleCacheKey = urlsToCacheKeys.get(possibleURL);
  26. if (possibleCacheKey) {
  27. return possibleCacheKey;
  28. }
  29. }
  30. };