Documentation
¶
Index ¶
- type Item
- type Map
- func (m *Map[K, V]) All() iter.Seq[Item[K, V]]
- func (m *Map[K, V]) Clear()
- func (m *Map[K, V]) Delete(item Item[K, V])
- func (m *Map[K, V]) DeleteKey(k K) bool
- func (m *Map[K, V]) Exists(k K) bool
- func (m *Map[K, V]) Get(k K) Item[K, V]
- func (m *Map[K, V]) GetNoTouch(k K) Item[K, V]
- func (m *Map[K, V]) GetOrCreate(k K) (Item[K, V], bool)
- func (m *Map[K, V]) Len() int
- func (m *Map[K, V]) NullItem() Item[K, V]
- func (m *Map[K, V]) Set(k K, v V) Item[K, V]
- func (m *Map[K, V]) Touch(item Item[K, 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 }
ttlmap.Map is a key value store where unused items are automatically removed when they expire. It is not safe to call any method concurrently from different goroutines. This includes iterating on the expired items sequence.
func New ¶
func New[K comparable, V any](ttl, accuracy time.Duration) (*Map[K, V], <-chan iter.Seq[Item[K, V]])
New creates a new ttlmap. ttl sets the minimum lifetime of each item. ttl must be at least 1ms; accuracy defines how much the item lifetime is allowed to be extended to avoid resetting the expiration timer. It must be less than ttl and can be 0. This version returns the map instance and a channel where item iterators are received. The iterators provide a notification on which items are expired. Iterating through the items is required in order for the items to be removed from the map.
func NewAsync ¶
func NewAsync[K comparable, V any](ttl, accuracy time.Duration, handleExpired func(iter.Seq[Item[K, V]])) *Map[K, V]
NewAsync is like New, but instead of returning a channel, it gets a method which is called when items expire. Note that the returned iterator must not be used concurrently with other ttlmap methods, so proper syncrhonization must still be ensured externally.