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(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](f Filler[K, V], retryErrors bool) *GeneriCache[K, V]
NewGeneriCache - factory method for GeneriCache. Use this to initialize. f is a filler method meant to fill the cache on cache miss. retryErrors indicates whether or not an error received from f 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 f more than once per key. If true, it will call f on subsequent Get() calls until error is nil.
func (*GeneriCache[K, V]) Get ¶
func (gc *GeneriCache[K, V]) Get(k K) (V, error)
Get - Get a value from the cache. On cache miss, it will call the Filler function.