cache

package
v1.60.1 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fetcher added in v1.52.1

type Fetcher[K comparable, V any] func(context.Context, K) (V, error)

Fetcher is a function which can fetch an item which doesn't yet exist in the cache.

type Local added in v1.52.1

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

Local is a generic in-memory cache with builtin in fetching of missing items.

func NewLocal added in v1.52.1

func NewLocal[K comparable, V any](fetch Fetcher[K, V], ttl time.Duration) *Local[K, V]

NewLocal creates a new in-memory cache.

func (*Local[K, V]) Clear added in v1.52.2

func (c *Local[K, V]) Clear()

Clear removes all items from the cache.

func (*Local[K, V]) Get added in v1.52.1

func (c *Local[K, V]) Get(key K) V

Get returns the item with the given key from the cache or the type's zero value.

func (*Local[K, V]) GetOrFetch added in v1.52.2

func (c *Local[K, V]) GetOrFetch(ctx context.Context, key K) (V, error)

GetOrFetch looks for the item in cache and if not found tries to fetch it.

func (*Local[K, V]) Len added in v1.52.1

func (c *Local[K, V]) Len() int

Len returns the number of items in the cache.

func (*Local[K, V]) Set added in v1.52.2

func (c *Local[K, V]) Set(key K, val V)

Set overwrites the value for the given key.

func (*Local[K, V]) Start added in v1.52.1

func (c *Local[K, V]) Start()

Start starts the routine to eliminate expired items from the cache.

func (*Local[K, V]) Stop added in v1.52.1

func (c *Local[K, V]) Stop()

Stop stops that routine.

Jump to

Keyboard shortcuts

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