UNPKG

react-query

Version:

Hooks for managing, caching and syncing asynchronous and remote data in React

27 lines (22 loc) 658 B
import { isServer, isValidTimeout } from './utils'; export class Removable { destroy() { this.clearGcTimeout(); } scheduleGc() { this.clearGcTimeout(); if (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 : isServer ? Infinity : 5 * 60 * 1000); } clearGcTimeout() { clearTimeout(this.gcTimeout); this.gcTimeout = undefined; } }