Documentation
¶
Overview ¶
This file implements a no-op cache that always misses and never stores values. NoCache is useful for testing or when caching should be disabled without changing code.
This file implements a high-performance cache using Ristretto v2. It provides thread-safe caching with singleflight to prevent duplicate loads.
This file adapts fabric-smart-client's generic second-chance cache.Map to the Get/Add/Delete/GetOrLoad shape this package's cache consumers expect, the same shape the fabric-smart-client secondcache package exposed before it was removed upstream.
Index ¶
- Constants
- func NewDefaultRistrettoCache[T any]() (*ristrettoCache[T], error)
- func NewRistrettoCache[T any](config *ristretto.Config[string, T]) (*ristrettoCache[T], error)
- func NewRistrettoCacheWithSize[T any](maxCost int64) (*ristrettoCache[T], error)
- type Config
- type NoCache
- type SecondChanceCache
Constants ¶
const ( // ZeroCost with this ristretto uses the Cost function defined in its configuration ZeroCost = 0 // Default Ristretto configuration values DefaultNumCounters = 1e6 // 1 million DefaultMaxCost = 1e8 // 100 million DefaultBufferItems = 64 )
Variables ¶
This section is empty.
Functions ¶
func NewRistrettoCache ¶
NewRistrettoCache creates and returns a new ristretto-based cache implementation.
Types ¶
type SecondChanceCache ¶ added in v0.26.0
type SecondChanceCache[T any] struct { // contains filtered or unexported fields }
SecondChanceCache adapts fabric-smart-client's cache.Map to the Get/Add/Delete/GetOrLoad shape used by this package's consumers.
func NewSecondChanceCache ¶ added in v0.26.0
func NewSecondChanceCache[T any](size, buffer int) *SecondChanceCache[T]
NewSecondChanceCache returns a cache holding at most size entries, evicting buffer of them per victim scan once full. See fabric-smart-client's cache.NewSecondChanceCache for the eviction policy.
func (*SecondChanceCache[T]) Add ¶ added in v0.26.0
func (c *SecondChanceCache[T]) Add(key string, value T)
func (*SecondChanceCache[T]) Delete ¶ added in v0.26.0
func (c *SecondChanceCache[T]) Delete(key string)
func (*SecondChanceCache[T]) Get ¶ added in v0.26.0
func (c *SecondChanceCache[T]) Get(key string) (T, bool)
func (*SecondChanceCache[T]) GetOrLoad ¶ added in v0.26.0
func (c *SecondChanceCache[T]) GetOrLoad(key string, loader func() (T, error)) (T, bool, error)
GetOrLoad returns the cached value for key, or loads it via loader on a miss. Concurrent misses for the same key are collapsed via singleflight so loader runs once.