MCPcopy Create free account
hub / github.com/authorizerdev/authorizer / DeleteCacheByPrefix

Method DeleteCacheByPrefix

internal/memory_store/redis/cache.go:38–59  ·  view source on GitHub ↗

DeleteCacheByPrefix removes all cache entries whose keys start with the given prefix. Uses SCAN to avoid blocking Redis on large datasets.

(prefix string)

Source from the content-addressed store, hash-verified

36// DeleteCacheByPrefix removes all cache entries whose keys start with the given prefix.
37// Uses SCAN to avoid blocking Redis on large datasets.
38func (p *provider) DeleteCacheByPrefix(prefix string) error {
39 pattern := cachePrefix + prefix + "*"
40 var cursor uint64
41 for {
42 keys, nextCursor, err := p.store.Scan(p.ctx, cursor, pattern, 100).Result()
43 if err != nil {
44 p.dependencies.Log.Debug().Err(err).Msg("Error scanning cache keys from redis")
45 return err
46 }
47 if len(keys) > 0 {
48 if err := p.store.Del(p.ctx, keys...).Err(); err != nil {
49 p.dependencies.Log.Debug().Err(err).Msg("Error deleting cache keys from redis")
50 return err
51 }
52 }
53 cursor = nextCursor
54 if cursor == 0 {
55 break
56 }
57 }
58 return nil
59}

Callers

nothing calls this directly

Calls 2

ScanMethod · 0.80
DelMethod · 0.80

Tested by

no test coverage detected