MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / GetSuggestionCacheStats

Function GetSuggestionCacheStats

pkg/errors/cache.go:154–173  ·  view source on GitHub ↗

GetSuggestionCacheStats returns a snapshot of the current keyword suggestion cache metrics. The returned struct is safe to read without any additional locking. Use this in observability dashboards or benchmarks to track cache efficiency. Example: stats := errors.GetSuggestionCacheStats() fmt.Pri

()

Source from the content-addressed store, hash-verified

152// stats := errors.GetSuggestionCacheStats()
153// fmt.Printf("Cache hit rate: %.1f%%\n", stats.HitRate*100)
154func GetSuggestionCacheStats() SuggestionCacheStats {
155 hits := atomic.LoadUint64(&suggestionCache.hits)
156 misses := atomic.LoadUint64(&suggestionCache.misses)
157 evictions := atomic.LoadUint64(&suggestionCache.evictions)
158
159 var hitRate float64
160 total := hits + misses
161 if total > 0 {
162 hitRate = float64(hits) / float64(total)
163 }
164
165 return SuggestionCacheStats{
166 Size: suggestionCache.size(),
167 MaxSize: suggestionCache.maxSize,
168 Hits: hits,
169 Misses: misses,
170 Evictions: evictions,
171 HitRate: hitRate,
172 }
173}
174
175// ResetSuggestionCacheStats zeroes all hit, miss, and eviction counters in the
176// keyword suggestion cache without clearing cached entries. Call this at the start

Callers 2

Calls 1

sizeMethod · 0.45

Tested by 2