patchCache.ts
| 1 | import { MAX_PATCH_CACHE } from "../constants.ts"; |
| 2 | |
| 3 | export type ApplyResult = { status: "clean" | "conflict"; output: string }; |
| 4 | const cache = new Map<number, ApplyResult>(); |
| 5 | |
| 6 | export 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 |