/**
 * In-process cache for deserialized `memory.db` artifacts (Cuckoo filter, Merkle row).
 * Same idea as the MCP `cache` tool (`clawql-cache.ts`): ephemeral, per-process, invalidated when the
 * backing file changes. Keys include `mtimeMs` + `size` so any `persistDb` write misses the cache.
 */
const merkleByAbsDb = new Map();
const cuckooByAbsDb = new Map();
/** Test helper — clears artifact caches so vitest cases do not leak state. */
export function resetMemoryDbArtifactCachesForTests() {
    merkleByAbsDb.clear();
    cuckooByAbsDb.clear();
}
/** Call after writing `memory.db` (e.g. `persistDb`) so readers reload. */
export function invalidateMemoryDbArtifactCaches(absDbPath) {
    merkleByAbsDb.delete(absDbPath);
    cuckooByAbsDb.delete(absDbPath);
}
export function getCachedMerkleSnapshot(absDbPath, sig) {
    const e = merkleByAbsDb.get(absDbPath);
    if (!e || e.sig !== sig)
        return undefined;
    return e.row;
}
export function setCachedMerkleSnapshot(absDbPath, sig, row) {
    merkleByAbsDb.set(absDbPath, { sig, row });
}
export function getCachedCuckooFilter(absDbPath, sig) {
    const e = cuckooByAbsDb.get(absDbPath);
    if (!e || e.sig !== sig)
        return undefined;
    return e.filter;
}
export function setCachedCuckooFilter(absDbPath, sig, filter) {
    cuckooByAbsDb.set(absDbPath, { sig, filter });
}
