removable.esm.js 761 B

123456789101112131415161718192021222324252627282930313233
  1. import { isValidTimeout, isServer } from './utils.esm.js';
  2. class Removable {
  3. destroy() {
  4. this.clearGcTimeout();
  5. }
  6. scheduleGc() {
  7. this.clearGcTimeout();
  8. if (isValidTimeout(this.cacheTime)) {
  9. this.gcTimeout = setTimeout(() => {
  10. this.optionalRemove();
  11. }, this.cacheTime);
  12. }
  13. }
  14. updateCacheTime(newCacheTime) {
  15. // Default to 5 minutes (Infinity for server-side) if no cache time is set
  16. this.cacheTime = Math.max(this.cacheTime || 0, newCacheTime != null ? newCacheTime : isServer ? Infinity : 5 * 60 * 1000);
  17. }
  18. clearGcTimeout() {
  19. if (this.gcTimeout) {
  20. clearTimeout(this.gcTimeout);
  21. this.gcTimeout = undefined;
  22. }
  23. }
  24. }
  25. export { Removable };
  26. //# sourceMappingURL=removable.esm.js.map