cache

package
v0.12.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

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.

Index

Constants

View Source
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 NewDefaultRistrettoCache

func NewDefaultRistrettoCache[T any]() (*ristrettoCache[T], error)

func NewRistrettoCache

func NewRistrettoCache[T any](config *ristretto.Config[string, T]) (*ristrettoCache[T], error)

NewRistrettoCache creates and returns a new ristretto-based cache implementation.

func NewRistrettoCacheWithSize added in v0.10.0

func NewRistrettoCacheWithSize[T any](maxCost int64) (*ristrettoCache[T], error)

Types

type Config

type Config[K ristretto.Key, V any] = ristretto.Config[K, V]

Config is a shortcut for the ristretto Configuration.

type NoCache

type NoCache[T any] struct {
}

NoCache implements a dummy cache that does nothing

func NewNoCache

func NewNoCache[T any]() *NoCache[T]

NewNoCache returns a new instance of NoCache

func (*NoCache[T]) Add

func (n *NoCache[T]) Add(key string, value T)

func (*NoCache[T]) Delete

func (n *NoCache[T]) Delete(key string)

func (*NoCache[T]) Get

func (n *NoCache[T]) Get(key string) (T, bool)

func (*NoCache[T]) GetOrLoad

func (n *NoCache[T]) GetOrLoad(key string, loader func() (T, error)) (T, bool, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL