UNPKG

@toolpad/core

Version:

Dashboard framework powered by Material UI.

34 lines (33 loc) 650 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DataSourceCache = void 0; class DataSourceCache { constructor(config) { this.cache = {}; this.ttl = config?.ttl ?? 300000; } set(key, value) { const expiry = Date.now() + this.ttl; this.cache[key] = { value, expiry }; } get(key) { const entry = this.cache[key]; if (!entry) { return undefined; } if (Date.now() > entry.expiry) { delete this.cache[key]; return undefined; } return entry.value; } clear() { this.cache = {}; } } exports.DataSourceCache = DataSourceCache;