"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.summaryCache = exports.SummaryCache = void 0;
exports.buildCacheKey = buildCacheKey;
const DEFAULT_TTL = 10 * 60 * 1000; // 10 minutes
function buildCacheKey(tableId, rowId, mode) {
    return `${tableId}:${rowId}:${mode}`;
}
class SummaryCache {
    constructor(ttl = DEFAULT_TTL) {
        this.store = new Map();
        this.inflight = new Map();
        this.ttl = ttl;
    }
    get(key) {
        const entry = this.store.get(key);
        if (!entry)
            return undefined;
        if (Date.now() - entry.updatedAt > this.ttl) {
            this.store.delete(key);
            return undefined;
        }
        return entry;
    }
    set(key, entry) {
        this.store.set(key, { ...entry, updatedAt: Date.now() });
    }
    delete(key) {
        this.store.delete(key);
    }
    clear() {
        this.store.clear();
    }
    getInflight(key) {
        return this.inflight.get(key);
    }
    setInflight(key, promise) {
        this.inflight.set(key, promise);
        promise.finally(() => this.inflight.delete(key));
    }
    hasInflight(key) {
        return this.inflight.has(key);
    }
    clearAll() {
        this.store.clear();
        this.inflight.clear();
    }
    getStats() {
        return { cacheSize: this.store.size, inflightSize: this.inflight.size };
    }
}
exports.SummaryCache = SummaryCache;
exports.summaryCache = new SummaryCache();
