Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheDriver ¶ added in v0.3.0
type CacheDriver interface { Add(key interface{}, value interface{}) Get(key interface{}) (interface{}, bool) }
CacheDriver stores the items you can use ARCCache or TwoQueueCache from github.com/hashicorp/golang-lru
func InMemoryCache ¶ added in v0.1.1
func InMemoryCache() CacheDriver
type ContextFactory ¶ added in v0.3.0
ContextFactory creates context to be used by LoadFunc
type Fetcher ¶ added in v0.3.0
type Fetcher[Key comparable, Value any] func(ctx context.Context, key Key) (Value, error)
Fetcher loads the value based on key
type InMemoryKeyLocker ¶ added in v0.3.0
type InMemoryKeyLocker[Key comparable] struct { // contains filtered or unexported fields }
func (*InMemoryKeyLocker[Key]) Lock ¶ added in v0.3.0
func (l *InMemoryKeyLocker[Key]) Lock(key Key) func()
Lock implements KeyLocker
type KeyLocker ¶ added in v0.3.0
type KeyLocker[Key comparable] interface { Lock(key Key) (unlock func()) }
type Loader ¶
type Loader[Key comparable, Value any] struct { // contains filtered or unexported fields }
Loader manage items in cache and fetch them if not exist
func New ¶
func New[Key comparable, Value any](fn Fetcher[Key, Value], ttl time.Duration, options ...Option) *Loader[Key, Value]
New creates new Loader
func NewLRU ¶
func NewLRU[Key comparable, Value any](fn Fetcher[Key, Value], ttl time.Duration, size int, options ...Option) *Loader[Key, Value]
NewLRU creates Loader with lru based cache
type Option ¶ added in v0.3.0
type Option func(cfg *config)
func WithContextFactory ¶ added in v0.3.0
func WithContextFactory(cf ContextFactory) Option
func WithDriver ¶ added in v0.3.0
func WithDriver(driver CacheDriver) Option
func WithErrorTTL ¶ added in v0.3.0
Click to show internal directories.
Click to hide internal directories.