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

Method SetCacheList

internal/repository/cache/check.go:126–138  ·  view source on GitHub ↗

SetCacheList 将审核记录列表写入缓存

(ctx context.Context, key string, checks []domain.Check, ttl time.Duration)

Source from the content-addressed store, hash-verified

124
125// SetCacheList 将审核记录列表写入缓存
126func (c *checkCache) SetCacheList(ctx context.Context, key string, checks []domain.Check, ttl time.Duration) error {
127 // 将[]domain.Check对象序列化为JSON格式
128 data, err := json.Marshal(checks)
129 if err != nil {
130 return err
131 }
132
133 // 设置随机化的TTL,防止缓存雪崩
134 randomTTL := ttl + time.Duration(randomInt(0, 300))*time.Second
135
136 // 将数据写入Redis
137 return c.client.Set(ctx, key, data, randomTTL).Err()
138}
139
140// GetCountCache 从缓存中获取审核记录的数量
141func (c *checkCache) GetCountCache(ctx context.Context, key string) (int64, error) {

Callers

nothing calls this directly

Calls 2

randomIntFunction · 0.85
SetMethod · 0.65

Tested by

no test coverage detected