cache

package
v3.1.19 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("cache: not found")

Functions

func Get

func Get[T any](ctx context.Context, key string, loader TypedLoader[T]) (T, error)

func Load

func Load[T any](c *Cache, ctx context.Context, key string, loader TypedLoader[T]) (T, error)

func SetDefaultStore

func SetDefaultStore(store Store)

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

func Default

func Default(opts ...Option) *Cache

func New

func New(store Store, opts ...Option) *Cache

func (*Cache) Delete

func (c *Cache) Delete(ctx context.Context, keys ...string) error

func (*Cache) Take

func (c *Cache) Take(ctx context.Context, key string, out any, loader Loader) error

type Loader

type Loader func(context.Context) (any, error)

type Option

type Option func(*options)

func CacheNil

func CacheNil(enabled bool) Option

func EmptyTTL

func EmptyTTL(ttl time.Duration) Option

func Jitter

func Jitter(jitter time.Duration) Option

func NotFound

func NotFound(fn func(error) bool) Option

func Prefix

func Prefix(prefix string) Option

func TTL

func TTL(ttl time.Duration) Option

type Store

type Store interface {
	Get(ctx context.Context, key string) (string, error)
	Set(ctx context.Context, key string, value any, ttl ...time.Duration) error
	Delete(ctx context.Context, keys ...string) error
}

func DefaultStore

func DefaultStore() Store

type TypedLoader

type TypedLoader[T any] func(context.Context) (T, error)

Jump to

Keyboard shortcuts

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