MCPcopy Create free account
hub / github.com/astercloud/aster / Clear

Method Clear

pkg/tools/cache.go:209–232  ·  view source on GitHub ↗

Clear 清空所有缓存

()

Source from the content-addressed store, hash-verified

207
208// Clear 清空所有缓存
209func (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 获取统计信息
235func (c *ToolCache) GetStats() *CacheStats {

Callers 1

TestToolCache_ClearFunction · 0.95

Calls

no outgoing calls

Tested by 1

TestToolCache_ClearFunction · 0.76