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

Method Set

util/cache/enhanced_two_level_cache.go:48–62  ·  view source on GitHub ↗

Set 设置缓存

(key string, data []byte, ttl time.Duration)

Source from the content-addressed store, hash-verified

46
47// Set 设置缓存
48func (c *EnhancedTwoLevelCache) Set(key string, data []byte, ttl time.Duration) error {
49 // 获取当前时间作为最后修改时间
50 now := time.Now()
51
52 // 先设置内存缓存(这是快速操作,直接在当前goroutine中执行)
53 c.memory.SetWithTimestamp(key, data, ttl, now)
54
55 // 异步设置磁盘缓存(这是IO操作,可能较慢)
56 go func(k string, d []byte, t time.Duration) {
57 // 使用独立的goroutine写入磁盘,避免阻塞调用者
58 _ = c.disk.Set(k, d, t)
59 }(key, data, ttl)
60
61 return nil
62}
63
64// SetMemoryOnly 仅更新内存缓存
65func (c *EnhancedTwoLevelCache) SetMemoryOnly(key string, data []byte, ttl time.Duration) error {

Callers 2

SetBothLevelsMethod · 0.45
FlushMemoryToDiskMethod · 0.45

Calls 1

SetWithTimestampMethod · 0.45

Tested by

no test coverage detected