MCPcopy Create free account
hub / github.com/GoSimplicity/LinkMe / SetCache

Method SetCache

internal/repository/cache/check.go:59–71  ·  view source on GitHub ↗

SetCache 将单个审核记录写入缓存

(ctx context.Context, key string, check domain.Check, ttl time.Duration)

Source from the content-addressed store, hash-verified

57
58// SetCache 将单个审核记录写入缓存
59func (c *checkCache) SetCache(ctx context.Context, key string, check domain.Check, ttl time.Duration) error {
60 // 将domain.Check对象序列化为JSON格式
61 data, err := json.Marshal(check)
62 if err != nil {
63 return err
64 }
65
66 // 设置随机化的TTL,防止缓存雪崩
67 randomTTL := ttl + time.Duration(randomInt(0, 300))*time.Second
68
69 // 将数据写入Redis
70 return c.client.Set(ctx, key, data, randomTTL).Err()
71}
72
73// ClearCache 清除缓存中的指定键
74func (c *checkCache) ClearCache(ctx context.Context, key string) error {

Callers

nothing calls this directly

Calls 2

randomIntFunction · 0.85
SetMethod · 0.65

Tested by

no test coverage detected