libcache

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const NotFoundErr string = "value not found in store"

Variables

View Source
var ProviderSet = wire.NewSet(NewStore)

Functions

This section is empty.

Types

type Key

type Key[T any] struct {
	// contains filtered or unexported fields
}

func NewKey

func NewKey[T any](store Store, key string, defaultFallBackFunc fallBackFunc[T], defaultOptions ...Option) *Key[T]

func (*Key[T]) Delete

func (k *Key[T]) Delete(ctx context.Context) error

func (*Key[T]) Get

func (k *Key[T]) Get(ctx context.Context) (*T, error)

func (*Key[T]) GetWithFallBack

func (k *Key[T]) GetWithFallBack(ctx context.Context, fallBackFunc fallBackFunc[T], options ...Option) (*T, error)

func (*Key[T]) GetWithTTL

func (k *Key[T]) GetWithTTL(ctx context.Context) (*T, time.Duration, error)

func (*Key[T]) Set

func (k *Key[T]) Set(ctx context.Context, value *T, options ...Option) error

type Map

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

func NewMap

func NewMap[K any, V any](store Store, baseKeyName string, keyNameFunc mapKeyNameFunc[K],
	defaultFallBackFunc mapFallBackFunc[K, V], defaultOptions ...Option) *Map[K, V]

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(ctx context.Context, key K) error

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(ctx context.Context, key K) (*V, error)

func (*Map[K, V]) GetWithFallBack

func (m *Map[K, V]) GetWithFallBack(ctx context.Context, key K,
	fallBackFunc mapFallBackFunc[K, V], options ...Option) (*V, error)

func (*Map[K, V]) GetWithTTL

func (m *Map[K, V]) GetWithTTL(ctx context.Context, key K) (*V, time.Duration, error)

func (*Map[K, V]) Set

func (m *Map[K, V]) Set(ctx context.Context, key K, value *V, options ...Option) error

type NotFoundError

type NotFoundError struct {
	// contains filtered or unexported fields
}

func (NotFoundError) Cause

func (e NotFoundError) Cause() error

func (NotFoundError) Error

func (e NotFoundError) Error() string

func (NotFoundError) Is

func (e NotFoundError) Is(err error) bool

func (NotFoundError) Unwrap

func (e NotFoundError) Unwrap() error

type Option

type Option func(o *Options)

Option represents a store option function.

func WithCost

func WithCost(cost int64) Option

WithCost allows setting the memory capacity used by the item when setting a value. Actually it seems to be used by Ristretto library only.

func WithExpiration

func WithExpiration(expiration time.Duration) Option

WithExpiration allows to specify an expiration time when setting a value.

type Options

type Options struct {
	Cost       int64
	Expiration time.Duration
}

func (*Options) IsEmpty

func (o *Options) IsEmpty() bool

type Store

type Store interface {
	Get(ctx context.Context, key any) (any, error)
	GetWithTTL(ctx context.Context, key any) (any, time.Duration, error)
	Set(ctx context.Context, key any, value any, options ...Option) error
	Delete(ctx context.Context, key any) error
	Clear(ctx context.Context) error
}

Store is the interface for all available stores Inspired by https://github.com/eko/gocache

func NewStore

func NewStore(conf *conf.Cache) (Store, error)

Jump to

Keyboard shortcuts

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