SetEmpty 缓存空对象,使用较短的过期时间
(ctx context.Context, key string)
| 108 | |
| 109 | // SetEmpty 缓存空对象,使用较短的过期时间 |
| 110 | func (c *postCache) SetEmpty(ctx context.Context, key string) error { |
| 111 | if key == "" { |
| 112 | return fmt.Errorf("无效的帖子ID: %s", key) |
| 113 | } |
| 114 | |
| 115 | // 空对象使用空字符串标记,不需要存储完整结构 |
| 116 | return c.client.Set(ctx, c.emptyKey(key), "1", time.Minute*5).Err() |
| 117 | } |
| 118 | |
| 119 | // IsEmpty 检查是否存在空对象标记 |
| 120 | func (c *postCache) IsEmpty(ctx context.Context, key string) (bool, error) { |