Documentation
¶
Overview ¶
Package cache provides a thread-safe LRU cache with TTL expiry, schema versioning, and singleflight de-duplication of concurrent loads.
WaxTap can run many concurrent extractions that need the same player data, so the cache keeps multiple entries and collapses concurrent loads for the same key into one loader call.
Schema versioning lets a format change invalidate every stale entry at once: bump SchemaVersion and old entries are treated as misses.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
MaxEntries int // 0 => default
TTL time.Duration // 0 => default
SchemaVersion int // entries from other versions are misses
}
Options configures a Store. NewStore fills zero values with defaults.
type Store ¶
type Store[V any] struct { // contains filtered or unexported fields }
Store is a generic LRU+TTL cache safe for concurrent use.
func (*Store[V]) Get ¶
Get returns the cached value for key if present, unexpired, and from the current schema version.
func (*Store[V]) GetOrLoad ¶
func (s *Store[V]) GetOrLoad(ctx context.Context, key string, load func(context.Context) (V, error)) (V, error)
GetOrLoad returns the cached value for key, or loads it exactly once across concurrent callers (singleflight) and caches the result. The loader's error is returned to all waiters and is not cached.