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
()
| 152 | // stats := errors.GetSuggestionCacheStats() |
| 153 | // fmt.Printf("Cache hit rate: %.1f%%\n", stats.HitRate*100) |
| 154 | func 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 |