MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / onResponse

Function onResponse

src/utils/cacheStatsState.ts:54–79  ·  view source on GitHub ↗
(usage: CacheUsage)

Source from the content-addressed store, hash-verified

52 * Returns the updated in-memory state.
53 */
54export function onResponse(usage: CacheUsage): MemState {
55 const sig = tokenSignature(usage)
56 const hitRate = computeHitRate(usage)
57
58 if (sig !== memState.signature) {
59 // New API response — reset the TTL clock
60 memState = {
61 signature: sig,
62 lastResetAt: Date.now(),
63 lastHitRate: hitRate,
64 }
65 // Persist asynchronously; intentionally fire-and-forget
66 if (sessionId !== null) {
67 const filePath = getStateFilePath(sessionId)
68 const toWrite: CacheStatsState = {
69 version: 1,
70 signature: sig,
71 lastResetAt: memState.lastResetAt,
72 lastHitRate: hitRate,
73 }
74 void writeStateAtomic(filePath, toWrite)
75 }
76 }
77
78 return { ...memState }
79}
80
81/** Read current in-memory state without triggering a response update. */
82export function getCacheStatsState(): MemState {

Callers 1

cacheStats.test.tsFile · 0.50

Calls 5

tokenSignatureFunction · 0.85
computeHitRateFunction · 0.85
getStateFilePathFunction · 0.85
writeStateAtomicFunction · 0.85
nowMethod · 0.80

Tested by

no test coverage detected