removable.js 833 B

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