WithTTL(ttl time.Duration) | Default expiration for all entries |
WithJitter(lambda float64, upperBound time.Duration) | Randomize TTL by +/-lambda (capped at upperBound) to prevent thundering herd |
WithJanitor() | Start background goroutine to evict expired entries. Mutually exclusive with WithoutLocking() |
WithLoaders(loaders ...Loader[K, V]) | Chain of loader functions for cache misses. Execute sequentially; later loaders receive only unmapped keys |
WithRevalidation(stale time.Duration, loaders ...Loader[K, V]) | Enable stale-while-revalidate. After TTL, entries become stale and trigger async refresh. Hard-expired after stale duration |
WithRevalidationErrorPolicy(policy) | hot.KeepOnError (keep stale value) or hot.DropOnError (drop on refresh failure) |
WithMissingCache(algorithm, capacity) | Dedicated cache for missing keys (independent eviction) |
WithMissingSharedCache() | Store missing keys in the main cache |
WithSharding(shards uint64, hasher Hasher[K]) | Split into N shards to reduce lock contention. Use powers of 2 |
WithCopyOnRead(fn func(V) V) | Clone values on retrieval to prevent external mutation |
WithCopyOnWrite(fn func(V) V) | Clone values on storage to capture snapshots |
WithPrometheusMetrics(cacheName string) | Enable Prometheus metrics collection |
WithEvictionCallback(fn func(K, V)) | Synchronous callback on eviction |
WithoutLocking() | Disable mutexes. Single-goroutine access only. Mutually exclusive with WithJanitor() |
WithWarmUp(fn func() (map[K]V, []K, error)) | Pre-populate cache on build. Returns values + missing keys + error |
WithWarmUpWithTimeout(timeout, fn) | Same as WarmUp with timeout protection |
Build() | Finalize and return *HotCache[K, V] |