react-query
Version:
Hooks for managing, caching and syncing asynchronous and remote data in React
35 lines (26 loc) • 755 B
JavaScript
;
exports.__esModule = true;
exports.Removable = void 0;
var _utils = require("./utils");
class Removable {
destroy() {
this.clearGcTimeout();
}
scheduleGc() {
this.clearGcTimeout();
if ((0, _utils.isValidTimeout)(this.cacheTime)) {
this.gcTimeout = setTimeout(() => {
this.optionalRemove();
}, this.cacheTime);
}
}
updateCacheTime(newCacheTime) {
// Default to 5 minutes (Infinity for server-side) if no cache time is set
this.cacheTime = Math.max(this.cacheTime || 0, newCacheTime != null ? newCacheTime : _utils.isServer ? Infinity : 5 * 60 * 1000);
}
clearGcTimeout() {
clearTimeout(this.gcTimeout);
this.gcTimeout = undefined;
}
}
exports.Removable = Removable;