| 292 | } |
| 293 | |
| 294 | func (c *ToolCache) evictOldest() { |
| 295 | // 找到最旧的条目 |
| 296 | var oldestKey string |
| 297 | var oldestTime time.Time |
| 298 | |
| 299 | for key, entry := range c.memoryCache { |
| 300 | if oldestKey == "" || entry.CreatedAt.Before(oldestTime) { |
| 301 | oldestKey = key |
| 302 | oldestTime = entry.CreatedAt |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | if oldestKey != "" { |
| 307 | if entry, ok := c.memoryCache[oldestKey]; ok { |
| 308 | delete(c.memoryCache, oldestKey) |
| 309 | c.stats.ItemCount-- |
| 310 | c.stats.TotalSize -= entry.Size |
| 311 | c.stats.Evictions++ |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | // 文件缓存操作 |
| 317 | |