Documentation
¶
Overview ¶
Package genericache is a simple cache with no evictions, no expiration.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Filler ¶
type Filler[K comparable, V any] func(key K) (V, error)
Filler is a function that is meant to fetch values on cache miss. An error returned from this function will be returned from the GeneriCache.Get() method.
type GeneriCache ¶
type GeneriCache[K comparable, V any] struct { // contains filtered or unexported fields }
GeneriCache implements a simple cache with no eviction.
func NewGeneriCache ¶
func NewGeneriCache[K comparable, V any](fillFunc Filler[K, V], retryErrors bool) *GeneriCache[K, V]
NewGeneriCache - factory method for GeneriCache. Use this to initialize. fillFunc is a filler method meant to fill the cache on cache miss. retryErrors indicates whether an error received from fillFunc should indicate to try the filler function on next Get() operation. If this is false, it will return the same error over and over and not call fillFunc more than once per key. If true, it will call fillFunc on subsequent Get() calls until error is nil.
func (*GeneriCache[K, V]) Get ¶
func (gc *GeneriCache[K, V]) Get(key K) (V, error)
Get - Get a value from the cache. On cache miss, it will call the Filler function.