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

Function calculateCacheHitRate

src/utils/cacheWarning.ts:55–73  ·  view source on GitHub ↗
(
  usage: Usage | null | undefined,
)

Source from the content-addressed store, hash-verified

53 * 返回值范围 0-100,null 表示无有效数据
54 */
55export function calculateCacheHitRate(
56 usage: Usage | null | undefined,
57): number | null {
58 if (!usage) return null
59
60 const { input_tokens, cache_creation_input_tokens, cache_read_input_tokens } =
61 usage
62
63 // 所有缓存字段为 0 表示无缓存数据
64 if (cache_read_input_tokens === 0 && cache_creation_input_tokens === 0) {
65 return null
66 }
67
68 const totalInputTokens =
69 input_tokens + cache_creation_input_tokens + cache_read_input_tokens
70 if (totalInputTokens === 0) return null
71
72 return (cache_read_input_tokens / totalInputTokens) * 100
73}
74
75/**
76 * 检测是否需要显示缓存警告

Callers 2

shouldShowCacheWarningFunction · 0.85
analyzeContextUsageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected