Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

Plugin.mjs 1.9 KiB

3 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. Copyright 2016 Google Inc. All Rights Reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. import {CacheableResponse} from './CacheableResponse.mjs';
  14. import './_version.mjs';
  15. /**
  16. * A class implementing the `cacheWillUpdate` lifecycle callback. This makes it
  17. * easier to add in cacheability checks to requests made via Workbox's built-in
  18. * strategies.
  19. *
  20. * @memberof workbox.cacheableResponse
  21. */
  22. class Plugin {
  23. /**
  24. * To construct a new cacheable response Plugin instance you must provide at
  25. * least one of the `config` properties.
  26. *
  27. * If both `statuses` and `headers` are specified, then both conditions must
  28. * be met for the `Response` to be considered cacheable.
  29. *
  30. * @param {Object} config
  31. * @param {Array<number>} [config.statuses] One or more status codes that a
  32. * `Response` can have and be considered cacheable.
  33. * @param {Object<string,string>} [config.headers] A mapping of header names
  34. * and expected values that a `Response` can have and be considered cacheable.
  35. * If multiple headers are provided, only one needs to be present.
  36. */
  37. constructor(config) {
  38. this._cacheableResponse = new CacheableResponse(config);
  39. }
  40. /**
  41. * @param {Object} options
  42. * @param {Response} options.response
  43. * @return {boolean}
  44. * @private
  45. */
  46. cacheWillUpdate({response}) {
  47. if (this._cacheableResponse.isResponseCacheable(response)) {
  48. return response;
  49. }
  50. return null;
  51. }
  52. }
  53. export {Plugin};