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

Method SetList

internal/repository/cache/post.go:217–231  ·  view source on GitHub ↗

SetList 设置帖子列表缓存

(ctx context.Context, page int, size int, posts []domain.Post)

Source from the content-addressed store, hash-verified

215
216// SetList 设置帖子列表缓存
217func (c *postCache) SetList(ctx context.Context, page int, size int, posts []domain.Post) error {
218 if page <= 0 || size <= 0 {
219 return fmt.Errorf("无效的分页参数: page=%d, size=%d", page, size)
220 }
221
222 data, err := json.Marshal(posts)
223 if err != nil {
224 return fmt.Errorf("序列化帖子列表数据失败: %v", err)
225 }
226
227 // 列表缓存使用随机过期时间
228 randomExpiration := c.expiration + time.Duration(rand.Int63n(300))*time.Second
229 key := fmt.Sprintf("%d_%d", page, size)
230 return c.client.Set(ctx, c.listKey(key), data, randomExpiration).Err()
231}
232
233// DelList 删除帖子列表缓存
234func (c *postCache) DelList(ctx context.Context, key string) error {

Callers

nothing calls this directly

Calls 2

listKeyMethod · 0.95
SetMethod · 0.65

Tested by

no test coverage detected