Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheGroup ¶
type CacheGroup[T comparable] struct { // contains filtered or unexported fields }
CacheGroup provides single flighting for grouping repeated calls for the same workload, as well as a cache that extends the lifetime of the returned result by a specific duration.
func NewCacheGroup ¶
func NewCacheGroup[T comparable](max int) *CacheGroup[T]
NewCacheGroup[T] creates a new cache group instance given the max number of keys to cache. If a new cache entry is added that exceeds the maximum, the oldest entry is evicted.
func (*CacheGroup[T]) DisableExpiration ¶
func (cg *CacheGroup[T]) DisableExpiration()
DisableExpiration will shutdown the expiration process which allows cache entries to remain until 'max' is exceeded.
func (*CacheGroup[T]) Do ¶
func (cg *CacheGroup[T]) Do(key string, factory func() (T, error)) (T, error)
Do accepts a group key and a factory function to execute a workload request. Any executions of Do() using an identical key will wait on the originating request rather than executing a new request, and the final result will be shared among any callers sharing the same key. Additionally, once returned, the workload for that key will remained cached. An expiration policy can be added for this cache by calling the WithExpiration method.
func (*CacheGroup[T]) WithExpiration ¶
func (cg *CacheGroup[T]) WithExpiration(expiry time.Duration, evictionInterval time.Duration) *CacheGroup[T]
WithExpiration assigns a cache expiration to cached entries, and starts an eviction process, which runs on the specified interval.