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

Method DelList

internal/repository/cache/post.go:234–270  ·  view source on GitHub ↗

DelList 删除帖子列表缓存

(ctx context.Context, key string)

Source from the content-addressed store, hash-verified

232
233// DelList 删除帖子列表缓存
234func (c *postCache) DelList(ctx context.Context, key string) error {
235 if key == "*" {
236 pattern := c.listPrefix + key
237 // 使用SCAN命令批量删除,每次扫描100个key
238 var cursor uint64
239 var keys []string
240
241 for {
242 var scanKeys []string
243 var err error
244 scanKeys, cursor, err = c.client.Scan(ctx, cursor, pattern, 100).Result()
245 if err != nil {
246 return fmt.Errorf("扫描缓存键失败: %v", err)
247 }
248
249 keys = append(keys, scanKeys...)
250
251 if cursor == 0 {
252 break
253 }
254 }
255
256 // 如果有key需要删除,则使用pipeline批量删除
257 if len(keys) > 0 {
258 pipe := c.client.Pipeline()
259 for _, key := range keys {
260 pipe.Del(ctx, key)
261 }
262 if _, err := pipe.Exec(ctx); err != nil {
263 return fmt.Errorf("批量删除缓存键失败: %v", err)
264 }
265 }
266
267 return nil
268 }
269 return c.client.Del(ctx, c.listKey(key)).Err()
270}
271
272// GetPubList 获取已发布帖子列表缓存
273func (c *postCache) GetPubList(ctx context.Context, page int, size int) ([]domain.Post, error) {

Callers

nothing calls this directly

Calls 3

listKeyMethod · 0.95
DelMethod · 0.65
ExecMethod · 0.65

Tested by

no test coverage detected