mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
The Session kept every document it loaded or created in memory for the life of the process: every conversation and session document ever touched, built-in and third-party. Now a cached document that no watch or document state observes leaves the cache once it was not read or written for `documentRetentionMs` (HarnessSettings and createSession options; default ten minutes, 0 drops it right after use, Infinity keeps documents; anything that is not a number of milliseconds means the default), and loads from Storage again on its next access. An observer pins the incarnation it observes and releases it when that incarnation retires. Eviction runs on the mutation line, after every commit outcome (published, no-write, rejected, failed settlement) and from one unreferenced timer for the next expiry, so a transaction never loses a tracker it holds. Where timers cannot be unreferenced only commits evict. Cache bookkeeping is contained: a throwing clock or setting never changes an operation's outcome. A hot document moves in the eviction order at most once per granule (a tenth of the retention, up to 1 s), keeping the fan-out bench at HEAD's speed. `npm test` runs the durable suite a second time with every unattached document evicted right after use. 5,000 conversations kept 26,000 documents and about 3.8 KB each; with a 50 ms retention, after waiting, none (bench:document-cache).
20 lines
658 B
TypeScript
20 lines
658 B
TypeScript
import { fileURLToPath } from "node:url";
|
|
import { defineConfig } from "vitest/config";
|
|
|
|
const durableSrcIndex = fileURLToPath(new URL("./src/index.ts", import.meta.url));
|
|
const durableSrcTesting = fileURLToPath(new URL("./src/testing/index.ts", import.meta.url));
|
|
|
|
export default defineConfig({
|
|
test: {
|
|
environment: "node",
|
|
setupFiles: ["./test/setup-document-retention.ts"],
|
|
},
|
|
resolve: {
|
|
conditions: ["source"],
|
|
alias: [
|
|
{ find: /^@earendil-works\/pi-durable$/, replacement: durableSrcIndex },
|
|
{ find: /^@earendil-works\/pi-durable\/testing$/, replacement: durableSrcTesting },
|
|
],
|
|
},
|
|
ssr: { resolve: { conditions: ["source"] } },
|
|
});
|