definition

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValNil   = fmt.Errorf("Val should not be nil")
	ErrNotFound = fmt.Errorf("Key not found")
)

Functions

This section is empty.

Types

type Cacher

type Cacher[T any] interface {
	// Set sets the value of given key if it is new to the cache.
	// Param val should not be nil.
	Set(ctx context.Context, key string, val T, ttls ...time.Duration) error
	// Get tries to fetch a value corresponding to the given key from the cache.
	// If error occurs during the first time fetching, it will be cached until the
	// sequential fetching triggered by the refresh goroutine succeed.
	Get(ctx context.Context, key string) (T, error)
	// Del deletes the value corresponding to the given key from the cache.
	Del(ctx context.Context, key string) error
}

Cacher ...

type CacherFactory

type CacherFactory[T any] interface {
	New(prefix string, fetcher Fetcher[T]) (Cacher[T], error)
}

CacherFactory ...

type Fetcher

type Fetcher[T any] func(key string) (T, error)

Fetcher ...

Jump to

Keyboard shortcuts

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