更新 cache/cache.go
This commit is contained in:
25
cache/cache.go
vendored
25
cache/cache.go
vendored
@@ -214,26 +214,23 @@ func (mc *MemoryCache) Stats() (entries int, size int64) {
|
||||
})
|
||||
return count, mc.currentSize
|
||||
}
|
||||
|
||||
// GetStats 返回详细的缓存统计信息
|
||||
func (mc *MemoryCache) GetStats() map[string]interface{} {
|
||||
entries, size := mc.Stats()
|
||||
|
||||
utilizationPercent := float64(0)
|
||||
if mc.maxSize > 0 {
|
||||
utilizationPercent = float64(size) / float64(mc.maxSize) * 100
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
"entries": entries,
|
||||
"size": size,
|
||||
"max_size": mc.maxSize,
|
||||
"utilization": float64(size) / float64(mc.maxSize) * 100,
|
||||
"size_bytes": size,
|
||||
"size_mb": float64(size) / 1024 / 1024,
|
||||
"max_size_bytes": mc.maxSize,
|
||||
"max_size_mb": float64(mc.maxSize) / 1024 / 1024,
|
||||
"utilization_pct": utilizationPercent,
|
||||
"ttl_seconds": int64(mc.ttl.Seconds()),
|
||||
"enabled": mc.maxSize > 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (mc *MemoryCache) Stats() (entries int, size int64) {
|
||||
count := 0
|
||||
mc.entries.Range(func(key, value interface{}) bool {
|
||||
count++
|
||||
return true
|
||||
})
|
||||
return count, mc.currentSize
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user