Skip to content

Commit 116a6e5

Browse files
author
StackMemory Bot (CLI)
committed
feat(cache): surface token savings inline during sessions
Log cache hits/misses/stores to stderr so users see savings in real-time: - HIT: tool name, tokens saved, session total, hit rate - STORE: tool name, tokens cached for future dedup - Exit summary already existed (unchanged)
1 parent 2943b9c commit 116a6e5

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

src/integrations/mcp/server.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,10 +1599,11 @@ class LocalStackMemoryMCP {
15991599
if (cached.hit && cached.entry) {
16001600
this.sessionCacheHits++;
16011601
this.sessionTokensSaved += cached.tokensSaved;
1602-
logger.debug('Cache hit', {
1603-
tool: name,
1604-
tokensSaved: cached.tokensSaved,
1605-
});
1602+
const total = this.sessionCacheHits + this.sessionCacheMisses;
1603+
const rate = ((this.sessionCacheHits / total) * 100).toFixed(0);
1604+
console.error(
1605+
`[cache] HIT ${name} — saved ~${cached.tokensSaved} tokens (session: ${this.sessionTokensSaved.toLocaleString()} total, ${rate}% hit rate)`
1606+
);
16061607
const cachedResult = JSON.parse(cached.entry.content);
16071608
toolCall.result = cachedResult;
16081609
toolCall.duration = Date.now() - startTime;
@@ -1925,7 +1926,16 @@ class LocalStackMemoryMCP {
19251926
if (!error && result && cacheKey) {
19261927
try {
19271928
const serialized = JSON.stringify(result);
1928-
this.contentCache.putByKey(cacheKey, serialized, `tool:${name}`);
1929+
const entry = this.contentCache.putByKey(
1930+
cacheKey,
1931+
serialized,
1932+
`tool:${name}`
1933+
);
1934+
if (entry.hitCount === 0) {
1935+
console.error(
1936+
`[cache] STORE ${name} — ~${entry.tokenCount} tokens cached for future dedup`
1937+
);
1938+
}
19291939
} catch {
19301940
// Cache store failure is non-fatal
19311941
}

0 commit comments

Comments
 (0)