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

Method Delete

pkg/cachep/local/local.go:91–114  ·  view source on GitHub ↗

Delete 从本地缓存和 Redis 中删除一个或多个键

(ctx context.Context, keys ...string)

Source from the content-addressed store, hash-verified

89
90// Delete 从本地缓存和 Redis 中删除一个或多个键
91func (cm *CacheManager) Delete(ctx context.Context, keys ...string) error {
92 // 并发删除本地缓存和Redis
93 errChan := make(chan error, 2)
94
95 go func() {
96 for _, key := range keys {
97 cm.localCache.Delete(key)
98 }
99 errChan <- nil
100 }()
101
102 go func() {
103 errChan <- cm.redisClient.Del(ctx, keys...).Err()
104 }()
105
106 // 等待两个操作完成
107 for i := 0; i < 2; i++ {
108 if err := <-errChan; err != nil {
109 return err
110 }
111 }
112
113 return nil
114}
115
116// SetEmptyCache 缓存空对象,防止缓存穿透
117func (cm *CacheManager) SetEmptyCache(ctx context.Context, key string, ttl time.Duration) error {

Callers

nothing calls this directly

Calls 2

DeleteMethod · 0.65
DelMethod · 0.65

Tested by

no test coverage detected