cache

package
v1.5.3 Latest Latest
Warning

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

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

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Options

func Options() *options

Types

type Cache

type Cache[K Key, V any] interface {
	Get(key K) (V, bool)
	Set(key K, value V, opts *options) bool
	Delete(key K)
	Has(key K) bool
	ForEach(f func(key K, value V) error) error
	Size() int
}

Cache is the unified interface for all cache implementations.

func NewLRUCache

func NewLRUCache[K Key, V any](
	numShards int,
	totalCapacity int,
	onInvalidate func(K, V),
) Cache[K, V]

type Key added in v1.5.2

type Key interface {
	comparable
	Bytes() []byte
}

Key is the constraint for cache keys. Bytes() is required instead of String() because sharded caches use it to compute the shard index, and raw bytes are significantly cheaper to hash than a formatted string — e.g. IPKey.String() formats an IP address and allocates, while IPKey.Bytes() returns the underlying array slice with zero allocation.

type LRUCache

type LRUCache[K Key, V any] struct {
	// contains filtered or unexported fields
}

func (*LRUCache[K, V]) Delete added in v1.5.0

func (c *LRUCache[K, V]) Delete(key K)

func (*LRUCache[K, V]) ForEach

func (c *LRUCache[K, V]) ForEach(f func(key K, value V) error) error

func (*LRUCache[K, V]) Get added in v1.5.0

func (c *LRUCache[K, V]) Get(key K) (V, bool)

func (*LRUCache[K, V]) Has

func (c *LRUCache[K, V]) Has(key K) bool

func (*LRUCache[K, V]) Set added in v1.5.0

func (c *LRUCache[K, V]) Set(key K, value V, opts *options) bool

func (*LRUCache[K, V]) Size

func (c *LRUCache[K, V]) Size() int

type TTLCache

type TTLCache[K Key, V any] struct {
	// contains filtered or unexported fields
}

func NewTTLCache

func NewTTLCache[K Key, V any](
	attrs TTLCacheAttrs,
) *TTLCache[K, V]

func (*TTLCache[K, V]) Delete added in v1.5.0

func (c *TTLCache[K, V]) Delete(key K)

func (*TTLCache[K, V]) ForEach

func (c *TTLCache[K, V]) ForEach(f func(key K, value V) error) error

func (*TTLCache[K, V]) ForceCleanup

func (c *TTLCache[K, V]) ForceCleanup()

func (*TTLCache[K, V]) Get added in v1.5.0

func (c *TTLCache[K, V]) Get(key K) (V, bool)

func (*TTLCache[K, V]) Has

func (c *TTLCache[K, V]) Has(key K) bool

func (*TTLCache[K, V]) Set added in v1.5.0

func (c *TTLCache[K, V]) Set(key K, value V, opts *options) bool

func (*TTLCache[K, V]) Size

func (c *TTLCache[K, V]) Size() int

type TTLCacheAttrs

type TTLCacheAttrs struct {
	NumOfShards     uint8
	CleanupInterval time.Duration
}

Jump to

Keyboard shortcuts

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