Clear 清空所有缓存
()
| 207 | |
| 208 | // Clear 清空所有缓存 |
| 209 | func (c *ToolCache) Clear() error { |
| 210 | if !c.config.Enabled { |
| 211 | return nil |
| 212 | } |
| 213 | |
| 214 | // 清空内存缓存 |
| 215 | if c.config.Strategy == CacheStrategyMemory || c.config.Strategy == CacheStrategyBoth { |
| 216 | c.memoryMu.Lock() |
| 217 | c.memoryCache = make(map[string]*CacheEntry) |
| 218 | c.stats.ItemCount = 0 |
| 219 | c.stats.TotalSize = 0 |
| 220 | c.memoryMu.Unlock() |
| 221 | } |
| 222 | |
| 223 | // 清空文件缓存 |
| 224 | if c.config.Strategy == CacheStrategyFile || c.config.Strategy == CacheStrategyBoth { |
| 225 | if err := os.RemoveAll(c.config.CacheDir); err != nil { |
| 226 | c.stats.Errors++ |
| 227 | return fmt.Errorf("failed to clear file cache: %w", err) |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | return nil |
| 232 | } |
| 233 | |
| 234 | // GetStats 获取统计信息 |
| 235 | func (c *ToolCache) GetStats() *CacheStats { |
no outgoing calls