Documentation ¶
Index ¶
- type Cache
- func (c *Cache[K, V]) Delete(key K) (ok bool)
- func (c *Cache[K, V]) Evict(n int) (evicted int)
- func (c *Cache[K, V]) Get(key K) (V, bool)
- func (c *Cache[K, V]) GetAndDelete(key K) (V, bool)
- func (c *Cache[K, V]) GetMany(keys ...K) map[K]V
- func (c *Cache[K, V]) Len() int
- func (c *Cache[K, V]) Range(fn func(K, V) bool)
- func (c *Cache[K, V]) Refresh(key K, ttl time.Duration) bool
- func (c *Cache[K, V]) Rekey(oldKey, newKey K) bool
- func (c *Cache[K, V]) Set(key K, value V, ttl time.Duration)
- func (c *Cache[K, V]) Swap(key K, value V) (V, bool)
- func (c *Cache[K, V]) Update(key K, value V) bool
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 }
func New ¶
func New[K comparable, V any]() *Cache[K, V]
New creates a news cache instance, using any comparable type for keys, and any type for values.
func (*Cache[K, V]) Evict ¶
Evict removes (at most) n items that expire earliest, returning the number of actually evicted items.
func (*Cache[K, V]) Get ¶
Get returns value and true, if key exists, of zero value and false if not found.
func (*Cache[K, V]) GetAndDelete ¶
GetAndDelete returns value and true, and deletes the key if it was found, of zero value and false if the key not found.
func (*Cache[K, V]) GetMany ¶ added in v0.0.3
func (c *Cache[K, V]) GetMany(keys ...K) map[K]V
GetMany returns key/value pairs as a map. Will not return non-existing keys/expired values.
func (*Cache[K, V]) Range ¶ added in v0.0.2
Range iterates over key/value pairs using supplied function until it returns false. Values are provided in the order of eviction. It is safe to manipulate the cache within the function.
func (*Cache[K, V]) Refresh ¶
Refresh sets new TTL for the given key, returning true if the key (still) exists.
func (*Cache[K, V]) Rekey ¶ added in v0.0.3
Rekey replaces value's key. Returns false if the old key is not present.