MCPcopy Create free account
hub / github.com/RioArisk/claudecode_api_RemoteControl / pruneChatCache

Function pruneChatCache

app/src/modules/chat-cache.js:96–118  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

94}
95
96export async function pruneChatCache() {
97 let records;
98 try {
99 records = await chatCacheReadAll();
100 } catch {
101 return;
102 }
103
104 records.sort((a, b) => (b.updatedAt || 0) - (a.updatedAt || 0));
105 let totalBytes = 0;
106 const removals = [];
107
108 records.forEach((record, idx) => {
109 const sizeBytes = Number.isFinite(record.sizeBytes) ? record.sizeBytes : estimateCacheBytes(record);
110 totalBytes += sizeBytes;
111 const overCount = idx >= CHAT_CACHE_MAX_SESSIONS;
112 const overTotal = totalBytes > CHAT_CACHE_MAX_TOTAL_BYTES;
113 const overSingle = sizeBytes > CHAT_CACHE_MAX_SESSION_BYTES;
114 if (overCount || overTotal || overSingle) removals.push(record.cacheKey);
115 });
116
117 await Promise.all(removals.map(cacheKey => chatCacheDelete(cacheKey).catch(() => {})));
118}

Callers 1

persistSessionCacheFunction · 0.90

Calls 3

chatCacheReadAllFunction · 0.70
estimateCacheBytesFunction · 0.70
chatCacheDeleteFunction · 0.70

Tested by

no test coverage detected