Documentation
¶
Overview ¶
Package ttlmap provides thread-safe map with expirable entries.
Index ¶
- type Map
- func (m *Map[K, V]) Get(key K) (value V, exists bool)
- func (m *Map[K, V]) GetAndRemove(key K) (value V, exists bool)
- func (m *Map[K, V]) Has(key K) bool
- func (m *Map[K, V]) Put(key K, value V)
- func (m *Map[K, V]) Remove(key K) bool
- func (m *Map[K, V]) Start(ctx context.Context) (stop func())
- func (m *Map[K, V]) Update(key K, cb func(value V) V) bool
- func (m *Map[K, V]) Upsert(key K, cb func(exists bool, value V) V)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map is a map with expirable elements.
func New ¶
New creates a new map with expirable elements. Whenever a key-value pair is inserted, a cleanup bucket is chosen and the inserted key-value pair is put into the bucket. With the interval of `ttl / numBuckets` a cleanup bucket is chosen and every expired element in that bucket is removed from the map (and from the bucket).
func (*Map[K, V]) GetAndRemove ¶
GetAndRemove removes an element from the map and returns it.
Click to show internal directories.
Click to hide internal directories.