Files
openclaw/src/config/cache-utils.test.ts
Peter Steinberger c440ae3e86 refactor(sessions): collapse legacy JSON store (#113075)
* refactor(sessions): collapse legacy JSON store

* chore(sessions): ratchet legacy importer boundary

* fix(sessions): align cleanup checks
2026-07-23 09:36:48 -07:00

40 lines
1019 B
TypeScript

// Covers synchronous config cache behavior.
import { describe, expect, it } from "vitest";
import { createExpiringMapCache } from "./cache-utils.js";
describe("createExpiringMapCache", () => {
it("expires entries on read after the TTL", () => {
let now = 1_000;
const cache = createExpiringMapCache<string, string>({
ttlMs: 5_000,
clock: () => now,
});
cache.set("alpha", "a");
expect(cache.get("alpha")).toBe("a");
now = 6_001;
expect(cache.get("alpha")).toBeUndefined();
expect(cache.size()).toBe(0);
});
it("supports dynamic TTLs and opportunistic pruning", () => {
let now = 1_000;
let ttlMs = 5_000;
const cache = createExpiringMapCache<string, string>({
ttlMs: () => ttlMs,
pruneIntervalMs: 1_000,
clock: () => now,
});
cache.set("stale", "old");
now = 7_000;
ttlMs = 2_000;
cache.set("fresh", "new");
expect(cache.get("stale")).toBeUndefined();
expect(cache.keys()).toEqual(["fresh"]);
});
});