MCPcopy Create free account
hub / github.com/anus-dev/ANUS / write

Function write

packages/core/src/utils/filesearch/crawlCache.ts:41–58  ·  view source on GitHub ↗
(key: string, results: string[], ttlMs: number)

Source from the content-addressed store, hash-verified

39 * Writes data to the in-memory cache and sets a timer to evict it after the TTL.
40 */
41export const write = (key: string, results: string[], ttlMs: number): void => {
42 // Clear any existing timer for this key to prevent premature deletion
43 if (cacheTimers.has(key)) {
44 clearTimeout(cacheTimers.get(key)!);
45 }
46
47 // Store the new data
48 crawlCache.set(key, results);
49
50 // Set a timer to automatically delete the cache entry after the TTL
51 const timerId = setTimeout(() => {
52 crawlCache.delete(key);
53 cacheTimers.delete(key);
54 }, ttlMs);
55
56 // Store the timer handle so we can clear it if the entry is updated
57 cacheTimers.set(key, timerId);
58};
59
60/**
61 * Clears the entire cache and all active timers.

Callers 1

crawlCache.test.tsFile · 0.85

Calls 2

getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected