cache

package
v0.0.0-...-0c66be6 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 11 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = cacheerrors.ErrNotFound

Functions

func Get

func Get[RESULT any](cache *Cache, key string, validate func(RESULT) error) (item RESULT, err error)

Get has to be a generic function because else we would lose the type information on l2 cache promotion to l2

func NoValidation

func NoValidation[T any](T) error

func Use

func Use[T any](cache *Cache, key string, get func() (T, error), validate func(T) error, exp time.Duration, l2Exp ...time.Duration) (result T, err error)

func UseWithExpInGet

func UseWithExpInGet[T any](cache *Cache, key string, get func() (T, time.Duration, error), validate func(T) error, fallbackExp time.Duration) (result T, err error)

Types

type Cache

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

func New

func New(config Config) (cache *Cache, err error)

func (*Cache) Close

func (this *Cache) Close() (err error)

func (*Cache) Remove

func (this *Cache) Remove(key string) (err error)

func (*Cache) Reset

func (this *Cache) Reset() (err error)

func (*Cache) Set

func (this *Cache) Set(key string, value interface{}, exp time.Duration, l2Exp ...time.Duration) (err error)

type CacheImpl

type CacheImpl = interfaces.CacheImpl

type Config

type Config struct {
	L1                            CacheImpl                 //optional, defaults to localcache.Cache (or L1Provider if provided) with 60s cache duration and 1s cleanup interval
	L1Provider                    func() (CacheImpl, error) //optional, may be used to create L1
	L2                            CacheImpl                 //optional
	L2Provider                    func() (CacheImpl, error) //optional, may be used to create L2
	Fallback                      *fallback.Fallback        //optional, only used in Use() and UseWithExpInGet() as a fallback to the get parameter
	FallbackProvider              func() (*fallback.Fallback, error)
	Debug                         bool
	ReadCacheHook                 func(duration time.Duration) //optional
	CacheMissHook                 func()                       //optional
	CacheInvalidationSignalHooks  map[Signal]ToKey
	CacheInvalidationSignalBroker *signal.Broker //optional, defaults to signal.DefaultBroker if CacheInvalidationSignalHooks is used
}

type Signal

type Signal = signal.Signal

type ToKey

type ToKey = func(signalValue string) (cacheKey string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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