Documentation
¶
Overview ¶
Package ttlcache provides a cache where items expire
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K comparable, V any] struct { // contains filtered or unexported fields }
Cache caches values of V using keys of K. Cache operations are concurrency-safe
func New ¶
func New[K comparable, V any](ctx context.Context, lifetime, cleanupInterval time.Duration) Cache[K, V]
New creates a new cache that invalidates items older than lifetime, pruning expired items every cleanupInterval. It launches a goroutine to perform this cleanup which exits when ctx is cancelled.
func (Cache[K, V]) Cleanup ¶
func (c Cache[K, V]) Cleanup()
Cleanup removes expired items from the cache.
func (Cache[K, V]) Delete ¶
func (c Cache[K, V]) Delete(k K)
Delete a value from the cache. Deleting a key that isn't present is safe
func (Cache[K, V]) Get ¶
Get a value from cache. The bool return value indicates whether or not the key was present.
Click to show internal directories.
Click to hide internal directories.