fix(cache): harden providers and default cache handling

Make cache-write failures non-fatal in GetOrSet/Remember, replace the
unsynchronised default cache with an atomic pointer, fix tag-index leaks
and write-lock-on-read in the memory provider, add a janitor, closed
state and byte copies, hash/namespace memcache keys with CAS tag index,
gate Clear behind AllowFlush, return ErrNotFound without the key, and
allowlist Redis stats. Mark audit status.
This commit is contained in:
Hein
2026-09-30 13:13:06 +02:00
parent 652621a70e
commit 9533c3a0ed
9 changed files with 648 additions and 262 deletions
+10
View File
@@ -2,9 +2,14 @@ package cache
import (
"context"
"errors"
"time"
)
// ErrFlushNotAllowed is returned by Clear on shared-server providers (Redis, Memcache)
// unless AllowFlush is set in their config, because Clear flushes the whole server/DB.
var ErrFlushNotAllowed = errors.New("cache: Clear flushes the entire server; set AllowFlush in the provider config to permit it")
// Provider defines the interface that all cache providers must implement.
type Provider interface {
// Get retrieves a value from the cache by key.
@@ -58,8 +63,13 @@ type Options struct {
DefaultTTL time.Duration
// MaxSize is the maximum number of items (for in-memory provider).
// 0 selects the default (10000); a negative value means unbounded.
MaxSize int
// CleanupInterval is how often the in-memory provider removes expired items
// (default: 1 minute).
CleanupInterval time.Duration
// EvictionPolicy determines how items are evicted (LRU, LFU, etc).
EvictionPolicy string
}