cache

package
v14.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrWalkStop = errors.New("stop walking")

ErrWalkStop is used to stop walking over the cache items.

Functions

This section is empty.

Types

type Cache

type Cache[T any] interface {
	Get(ctx context.Context, key string) (*T, bool, error)
	Set(ctx context.Context, key string, info *T) error
	Delete(ctx context.Context, key string) error
}

Cache is an interface for caching information.

type CacheIterator

type CacheIterator[T any] interface {
	Cache[T]

	Walk(ctx context.Context, fn func(key string, value *T) error) error
	First(ctx context.Context, fn func(value *T) bool) (string, *T, bool, error)
}

CacheIterator is an interface for iterating over a cache.

func NewMemoryCache

func NewMemoryCache[T any](maxCount int) CacheIterator[T]

NewMemoryCache creates a new MemoryCache with the specified maximum count. If maxCount is zero or negative, a default value is calculated based on the available memory.

Jump to

Keyboard shortcuts

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