Documentation ¶
Overview ¶
Package evcache implements a concurrent key-value cache with capacity overflow eviction, item expiry and deduplication.
Package evcache implements a key-value cache with capacity overflow eviction, item expiry and deduplication.
Index ¶
- type Cache
- func (c *Cache[K, V]) Evict(key K) (value V, ok bool)
- func (c *Cache[K, V]) Exists(key K) bool
- func (c *Cache[K, V]) Fetch(key K, ttl time.Duration, f func() (V, error)) (value V, err error)
- func (c *Cache[K, V]) Get(key K) (value V, exists bool)
- func (c *Cache[K, V]) Len() int
- func (c *Cache[K, V]) LoadOrStore(key K, ttl time.Duration, value V) (old V, loaded bool)
- func (c *Cache[K, V]) MustFetch(key K, ttl time.Duration, f func() V) (value V)
- func (c *Cache[K, V]) Range(f func(key K, value V) bool)
- func (c *Cache[K, V]) TryFetch(key K, f func() (V, time.Duration, error)) (value V, err error)
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 is an in-memory TTL cache with optional capacity.
func (*Cache[K, V]) Fetch ¶
Fetch loads or stores a value for key. If a value exists, f will not be called, otherwise f will be called to fetch the new value. It panics if f panics. Concurrent Fetches for the same key will block each other and return a single result.
func (*Cache[K, V]) LoadOrStore ¶
LoadOrStore loads or stores a value for key. If the key is being Fetched, LoadOrStore blocks until Fetch returns.