caching

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoadableCache

type LoadableCache[K comparable, V any] interface {
	// Get a value pair to the cache data by key.
	Get(ctx context.Context, k K) (V, error)
	// GetALL returns all key-value pairs in the cache data.
	GetALL(context.Context) map[K]V
	// Values returns all values in the cache data.
	Values(context.Context) []V
	// Set a value pair to the cache data by key.
	Set(ctx context.Context, k K, v V) error
	// Purge clears all cache data.
	Purge(context.Context)
	// TryPurgeAndReload try to refresh cache data, if refresh result is nil, return false.
	TryPurgeAndReload(context.Context) bool
	// Stop stop refresh cache data.
	Stop(context.Context)
	// Restart restart refresh cache data.
	Restart(context.Context)
}

func New

func New[K comparable, V any](opts ...Option[K, V]) LoadableCache[K, V]

type Option

type Option[K comparable, V any] func(*loadableCache[K, V])

func WithBlock

func WithBlock[K comparable, V any]() Option[K, V]

WithBlock block call first RefreshAfterWrite.

func WithExpiration

func WithExpiration[K comparable, V any](exp time.Duration) Option[K, V]

WithExpiration cache expiration, Automatically reload if timeout

func WithRefreshAfterWrite

func WithRefreshAfterWrite[K comparable, V any](f func() map[K]V) Option[K, V]

WithRefreshAfterWrite refresh data provider

func WithSize

func WithSize[K comparable, V any](size int) Option[K, V]

WithSize cache size limit.

func WithTracing

func WithTracing[K comparable, V any](provider trace.TracerProvider) Option[K, V]

WithTracing enable otel tracing

Jump to

Keyboard shortcuts

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