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

Method getFromFile

pkg/tools/cache.go:318–342  ·  view source on GitHub ↗

文件缓存操作

(key string)

Source from the content-addressed store, hash-verified

316// 文件缓存操作
317
318func (c *ToolCache) getFromFile(key string) (any, bool) {
319 filePath := c.getCacheFilePath(key)
320
321 // 读取文件
322 data, err := os.ReadFile(filePath)
323 if err != nil {
324 return nil, false
325 }
326
327 // 反序列化
328 var entry CacheEntry
329 if err := json.Unmarshal(data, &entry); err != nil {
330 c.stats.Errors++
331 return nil, false
332 }
333
334 // 检查是否过期
335 if entry.IsExpired() {
336 // 删除过期文件
337 _ = os.Remove(filePath)
338 return nil, false
339 }
340
341 return entry.Value, true
342}
343
344func (c *ToolCache) setToFile(key string, value any, ttl time.Duration) error {
345 // 确保缓存目录存在

Callers 2

GetMethod · 0.95

Calls 4

getCacheFilePathMethod · 0.95
IsExpiredMethod · 0.95
ReadFileMethod · 0.45
RemoveMethod · 0.45

Tested by 1