Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrWorkerNotRunning = errors.New("cache worker is not running")
)
Functions ¶
This section is empty.
Types ¶
type CacheEntry ¶
type ShieldedCache ¶
type ShieldedCache[T any] struct { // contains filtered or unexported fields }
ShieldedCache is embedded in-memory shielded cache. "Shielded" means that duplicate requests will not be processed, but instead, they will wait for an existing request to be processed and get the cached result from it.
func NewShieldedCache ¶
func NewShieldedCache[T any](gcInterval time.Duration) *ShieldedCache[T]
NewShieldedCache creates a new ShieldedCache instance with a customizeable gc interval - period between garbage collection of expired objects.
func (*ShieldedCache[T]) DeleteObject ¶ added in v1.0.2
func (s *ShieldedCache[T]) DeleteObject(key string)
func (*ShieldedCache[T]) Fetch ¶
func (s *ShieldedCache[T]) Fetch(key string, ttl time.Duration, fetchFunc func() (T, error)) (*CacheEntry[T], bool, error)
Fetch is the main read-write cache that acts as a middleware between actual fetch function and the application, creating a cache layer in between.
func (*ShieldedCache[T]) StartWorker ¶
func (s *ShieldedCache[T]) StartWorker(ctx context.Context) error
StartWorker starts the worker, the goroutine that periodically evicts expired objects in the cache. The GC interval is configured in ShieldedCache creation.
func (*ShieldedCache[T]) Usage ¶
func (s *ShieldedCache[T]) Usage() (int, int)
Usage returns the size of underlying maps for objects, and shields.