MCPcopy Create free account
hub / github.com/VPSDance/ai-proxy-rules / write

Method write

scripts/sync/cache.ts:141–159  ·  view source on GitHub ↗
(url: string, text: string)

Source from the content-addressed store, hash-verified

139 }
140
141 private async write(url: string, text: string): Promise<void> {
142 await mkdir(this.cacheDir, { recursive: true });
143
144 const file = this.cacheFile(url);
145 const existing = await readFile(file, "utf8").catch(() => null);
146 if (existing !== text) {
147 await writeFile(file, text, "utf8");
148 }
149
150 const index = await this.readIndex();
151 if (index[this.cacheKey(url)] !== url) {
152 index[this.cacheKey(url)] = url;
153 await writeFile(
154 this.indexFile(),
155 `${JSON.stringify(sortKeys(index), null, 2)}\n`,
156 "utf8"
157 );
158 }
159 }
160
161 private async read(url: string): Promise<{ text: string; cachedAt?: string } | null> {
162 const file = this.cacheFile(url);

Callers 1

cachedMethod · 0.95

Calls 5

cacheFileMethod · 0.95
readIndexMethod · 0.95
cacheKeyMethod · 0.95
indexFileMethod · 0.95
sortKeysFunction · 0.85

Tested by

no test coverage detected