cache

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 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

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

type KeyedCache

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

func NewKeyed

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

func (*KeyedCache[K, T]) GetOrFetch

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

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

func (*KeyedCache[K, T]) InvalidateAll

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

type StaleError

type StaleError struct {
	Err error
}

func (*StaleError) Error

func (e *StaleError) Error() string

func (*StaleError) Unwrap

func (e *StaleError) Unwrap() error

type TTL

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

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

func NewTTL

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

func (*TTL[V]) Delete

func (c *TTL[V]) Delete(key string)

Delete removes the entry for key, if present.

func (*TTL[V]) DeleteFunc

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

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

func (*TTL[V]) Put

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