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

Method Set

pkg/tools/cache.go:163–184  ·  view source on GitHub ↗

Set 设置缓存

(ctx context.Context, key string, value any, ttl time.Duration)

Source from the content-addressed store, hash-verified

161
162// Set 设置缓存
163func (c *ToolCache) Set(ctx context.Context, key string, value any, ttl time.Duration) error {
164 if !c.config.Enabled {
165 return nil
166 }
167
168 c.stats.Sets++
169
170 // 设置到内存缓存
171 if c.config.Strategy == CacheStrategyMemory || c.config.Strategy == CacheStrategyBoth {
172 c.setToMemory(key, value, ttl)
173 }
174
175 // 设置到文件缓存
176 if c.config.Strategy == CacheStrategyFile || c.config.Strategy == CacheStrategyBoth {
177 if err := c.setToFile(key, value, ttl); err != nil {
178 c.stats.Errors++
179 return fmt.Errorf("failed to set file cache: %w", err)
180 }
181 }
182
183 return nil
184}
185
186// Delete 删除缓存
187func (c *ToolCache) Delete(key string) error {

Callers 9

TestToolCache_ExpirationFunction · 0.95
TestToolCache_FileCacheFunction · 0.95
TestToolCache_DeleteFunction · 0.95
TestToolCache_ClearFunction · 0.95
TestToolCache_DisabledFunction · 0.95
TestToolCache_CleanupFunction · 0.95

Calls 2

setToMemoryMethod · 0.95
setToFileMethod · 0.95

Tested by 9

TestToolCache_ExpirationFunction · 0.76
TestToolCache_FileCacheFunction · 0.76
TestToolCache_DeleteFunction · 0.76
TestToolCache_ClearFunction · 0.76
TestToolCache_DisabledFunction · 0.76
TestToolCache_CleanupFunction · 0.76