mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-10-04 12:31:58 +00:00
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:
Vendored
+10
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user