Documentation ¶
Overview ¶
Package cache contains cache utilities and implementations
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Expiring ¶
Expiring is an interface for an expiring cache entry It provides a method to get the expiration time and the value
type ExpiringCache ¶
type ExpiringCache[T any] struct { // contains filtered or unexported fields }
ExpiringCache is a cache that expires entries after a certain time
func NewExpiringCache ¶
func NewExpiringCache[T any](ctx context.Context, cfg *ExpiringCacheConfig) *ExpiringCache[T]
NewExpiringCache creates a new ExpiringCache based on the configuration If the configuration is nil, the default eviction time is 30 minutes
func (*ExpiringCache[T]) Close ¶
func (ec *ExpiringCache[T]) Close()
Close stops the eviction routine and disallows setting new entries
func (*ExpiringCache[T]) Delete ¶
func (ec *ExpiringCache[T]) Delete(key string)
Delete deletes the entry from the cache
func (*ExpiringCache[T]) Get ¶
func (ec *ExpiringCache[T]) Get(key string) (T, bool)
Get returns the value of the entry and a boolean indicating if the entry exists
func (*ExpiringCache[T]) Set ¶
func (ec *ExpiringCache[T]) Set(key string, value T)
Set sets the value of the entry
func (*ExpiringCache[T]) Size ¶
func (ec *ExpiringCache[T]) Size() int
Size returns the number of entries in the cache. This is useful for testing purposes
type ExpiringCacheConfig ¶
ExpiringCacheConfig is the configuration for the ExpiringCache