UNPKG

@gecut/utilities

Version:

The ultimate utility toolkit from Gecut Company, crafted with TypeScript for optimal speed and efficiency. Designed to boost productivity with a suite of fast and optimized tools.

24 lines 740 B
import { InMemorySimpleCache } from './in-memory.simple.js'; export class InMemoryAdvancedCache extends InMemorySimpleCache { constructor() { super(...arguments); this.expiresMap = new Map(); } set(key, value, ttlMS) { super.set(key, value); if (ttlMS) { this.expiresMap.set(key, Math.max(0, Date.now() + ttlMS)); } } get(key) { const value = super.get(key); if (!this.expiresMap.has(key)) return value; const expireTime = this.expiresMap.get(key); if (expireTime && expireTime > Date.now()) return value; this.delete(key); return undefined; } } //# sourceMappingURL=in-memory.advanced.js.map