* Read-modify-write cycle under the sidecar mutex. Persists before updating * the in-memory cache so observers never see state that didn't make it to * disk. Entries that end up entirely default are dropped.
(update: (entries: Record<string, MemoryMetaEntry>) => void)
| 149 | * disk. Entries that end up entirely default are dropped. |
| 150 | */ |
| 151 | private async mutate(update: (entries: Record<string, MemoryMetaEntry>) => void): Promise<void> { |
| 152 | await this.lock.withLock("meta", async () => { |
| 153 | const meta = await this.load(); |
| 154 | const entries = { ...meta.entries }; |
| 155 | update(entries); |
| 156 | for (const [key, entry] of Object.entries(entries)) { |
| 157 | if (isEmptyEntry(entry)) delete entries[key]; |
| 158 | } |
| 159 | const next: MemoryMetaFile = { entries }; |
| 160 | await writeFileAtomic(this.metaPath, JSON.stringify(next, null, 2), { encoding: "utf-8" }); |
| 161 | this.cache = next; |
| 162 | }); |
| 163 | } |
| 164 | |
| 165 | /** Logical keys of all pinned memory files. */ |
| 166 | async getPinnedKeys(): Promise<Set<string>> { |
no test coverage detected