MCPcopy
hub / github.com/fish2018/pansou / recordCacheAccess

Function recordCacheAccess

plugin/plugin.go:377–395  ·  view source on GitHub ↗

recordCacheAccess 记录缓存访问次数,用于智能缓存策略(仅内存)

(key string)

Source from the content-addressed store, hash-verified

375
376// recordCacheAccess 记录缓存访问次数,用于智能缓存策略(仅内存)
377func recordCacheAccess(key string) {
378 // 更新缓存项的访问时间和计数
379 if cached, ok := apiResponseCache.Load(key); ok {
380 cachedItem := cached.(cachedResponse)
381 cachedItem.LastAccess = time.Now()
382 cachedItem.AccessCount++
383 apiResponseCache.Store(key, cachedItem)
384 }
385
386 // 更新全局访问计数
387 if count, ok := cacheAccessCount.Load(key); ok {
388 cacheAccessCount.Store(key, count.(int) + 1)
389 } else {
390 cacheAccessCount.Store(key, 1)
391 }
392
393 // 触发定期清理(异步执行,不阻塞当前操作)
394 go cleanupExpiredApiCache()
395}
396
397// ============================================================
398// 第六部分:BaseAsyncPlugin 结构和构造函数

Callers 2

AsyncSearchMethod · 0.85
AsyncSearchWithResultMethod · 0.85

Calls 1

cleanupExpiredApiCacheFunction · 0.85

Tested by

no test coverage detected