cachePolicy.js 951 B

123456789101112131415161718192021222324252627282930
  1. export function newCachePolicy() {
  2. return {
  3. maxAge: undefined,
  4. scope: undefined,
  5. restrict(hint) {
  6. if (hint.maxAge !== undefined &&
  7. (this.maxAge === undefined || hint.maxAge < this.maxAge)) {
  8. this.maxAge = hint.maxAge;
  9. }
  10. if (hint.scope !== undefined && this.scope !== 'PRIVATE') {
  11. this.scope = hint.scope;
  12. }
  13. },
  14. replace(hint) {
  15. if (hint.maxAge !== undefined) {
  16. this.maxAge = hint.maxAge;
  17. }
  18. if (hint.scope !== undefined) {
  19. this.scope = hint.scope;
  20. }
  21. },
  22. policyIfCacheable() {
  23. if (this.maxAge === undefined || this.maxAge === 0) {
  24. return null;
  25. }
  26. return { maxAge: this.maxAge, scope: this.scope ?? 'PUBLIC' };
  27. },
  28. };
  29. }
  30. //# sourceMappingURL=cachePolicy.js.map