cache

package
v1.19.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

func New

func New[T any](ttl time.Duration) *Cache[T]

func (*Cache[T]) GetOrFetch

func (c *Cache[T]) GetOrFetch(ctx context.Context, fetch func(ctx context.Context) (T, error)) (T, error)

type ErrStale

type ErrStale struct {
	Err error
}

func (*ErrStale) Error

func (e *ErrStale) Error() string

func (*ErrStale) Unwrap

func (e *ErrStale) Unwrap() error

type TTL added in v1.19.1

type TTL[V any] struct {
	// contains filtered or unexported fields
}

TTL is a concurrency-safe in-memory cache with per-entry expiration.

func NewTTL added in v1.19.1

func NewTTL[V any](ttl time.Duration) *TTL[V]

func (*TTL[V]) DeleteFunc added in v1.19.1

func (c *TTL[V]) DeleteFunc(fn func(key string, value V) bool)

DeleteFunc removes all entries where the predicate returns true.

func (*TTL[V]) Get added in v1.19.1

func (c *TTL[V]) Get(key string) (V, bool)

func (*TTL[V]) Put added in v1.19.1

func (c *TTL[V]) Put(key string, value V)

Jump to

Keyboard shortcuts

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