cachePolicy.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.newCachePolicy = void 0;
  4. function newCachePolicy() {
  5. return {
  6. maxAge: undefined,
  7. scope: undefined,
  8. restrict(hint) {
  9. if (hint.maxAge !== undefined &&
  10. (this.maxAge === undefined || hint.maxAge < this.maxAge)) {
  11. this.maxAge = hint.maxAge;
  12. }
  13. if (hint.scope !== undefined && this.scope !== 'PRIVATE') {
  14. this.scope = hint.scope;
  15. }
  16. },
  17. replace(hint) {
  18. if (hint.maxAge !== undefined) {
  19. this.maxAge = hint.maxAge;
  20. }
  21. if (hint.scope !== undefined) {
  22. this.scope = hint.scope;
  23. }
  24. },
  25. policyIfCacheable() {
  26. if (this.maxAge === undefined || this.maxAge === 0) {
  27. return null;
  28. }
  29. return { maxAge: this.maxAge, scope: this.scope ?? 'PUBLIC' };
  30. },
  31. };
  32. }
  33. exports.newCachePolicy = newCachePolicy;
  34. //# sourceMappingURL=cachePolicy.js.map