更新 cache/cache.go

This commit is contained in:
XOF
2025-12-15 01:55:28 +08:00
parent 7d4800efb9
commit 6d214bbced

5
cache/cache.go vendored
View File

@@ -36,6 +36,11 @@ func NewMemoryCache(maxSize int64, ttl time.Duration) *MemoryCache {
return mc return mc
} }
func (e *CacheEntry) Age() string {
age := time.Since(e.Timestamp)
return strconv.FormatInt(int64(age.Seconds()), 10)
}
func (mc *MemoryCache) Get(key string) (*CacheEntry, bool) { func (mc *MemoryCache) Get(key string) (*CacheEntry, bool) {
val, ok := mc.entries.Load(key) val, ok := mc.entries.Load(key)
if !ok { if !ok {