patchCache.ts
Raw
1import { MAX_PATCH_CACHE } from "../constants.ts";
2
3export type ApplyResult = { status: "clean" | "conflict"; output: string };
4const cache = new Map<number, ApplyResult>();
5
6export const patchCache = {
7 get: (id: number): ApplyResult | undefined => cache.get(id),
8 set: (id: number, result: ApplyResult) => {
9 if (cache.size >= MAX_PATCH_CACHE) {
10 cache.delete(cache.keys().next().value!);
11 }
12 cache.set(id, result);
13 },
14 invalidate: (id: number) => cache.delete(id),
15};
16