/**
 * Bounded, in-process TTL cache. Entries expire on read after their TTL and the
 * oldest entry is evicted when capacity is reached (Map preserves insertion
 * order, which we use as a coarse LRU on writes).
 *
 * Each process holds its own copy — there is no cross-process invalidation.
 * Callers that need stronger consistency should pair the TTL with an explicit
 * `delete()` on writes to the underlying data.
 */
export default class InMemoryTTLCache {
    constructor(maxEntries = 10000) {
        this.store = new Map();
        this.maxEntries = maxEntries;
    }
    set(key, value, ttlMs) {
        if (this.store.size >= this.maxEntries && !this.store.has(key)) {
            const oldest = this.store.keys().next().value;
            if (oldest !== undefined) {
                this.store.delete(oldest);
            }
        }
        this.store.delete(key);
        this.store.set(key, { value, expiresAt: Date.now() + ttlMs });
    }
    get(key) {
        const entry = this.store.get(key);
        if (!entry) {
            return undefined;
        }
        if (Date.now() > entry.expiresAt) {
            this.store.delete(key);
            return undefined;
        }
        return entry.value;
    }
    has(key) {
        return this.get(key) !== undefined;
    }
    delete(key) {
        this.store.delete(key);
    }
    clear() {
        this.store.clear();
    }
    size() {
        return this.store.size;
    }
}
//# sourceMappingURL=InMemoryTTLCache.js.map