cache

package
v1.19.4 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: BSD-3-Clause Imports: 5 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)

func (*Cache[T]) Invalidate added in v1.19.2

func (c *Cache[T]) Invalidate()

type ErrStale

type ErrStale struct {
	Err error
}

func (*ErrStale) Error

func (e *ErrStale) Error() string

func (*ErrStale) Unwrap

func (e *ErrStale) Unwrap() error

type KeyedCache added in v1.19.2

type KeyedCache[K comparable, T any] struct {
	// contains filtered or unexported fields
}

func NewKeyed added in v1.19.2

func NewKeyed[K comparable, T any]() *KeyedCache[K, T]

func (*KeyedCache[K, T]) GetOrFetch added in v1.19.2

func (c *KeyedCache[K, T]) GetOrFetch(
	ctx context.Context,
	key K,
	valid func(cached T) bool,
	fetch func(ctx context.Context) (T, error),
) (T, error)

func (*KeyedCache[K, T]) Invalidate added in v1.19.2

func (c *KeyedCache[K, T]) Invalidate(key K)

func (*KeyedCache[K, T]) InvalidateAll added in v1.19.2

func (c *KeyedCache[K, T]) InvalidateAll()

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