ttlmap

package
v0.0.0-...-225fc4e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item[K comparable, V any] = rankedmap.MapItem[K, timestamp, V]

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.

func (*Map[K, V]) All

func (m *Map[K, V]) All() iter.Seq[Item[K, V]]

func (*Map[K, V]) Clear

func (m *Map[K, V]) Clear()

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(item Item[K, V])

func (*Map[K, V]) DeleteKey

func (m *Map[K, V]) DeleteKey(k K) bool

func (*Map[K, V]) Exists

func (m *Map[K, V]) Exists(k K) bool

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(k K) Item[K, V]

func (*Map[K, V]) GetNoTouch

func (m *Map[K, V]) GetNoTouch(k K) Item[K, V]

func (*Map[K, V]) GetOrCreate

func (m *Map[K, V]) GetOrCreate(k K) (Item[K, V], bool)

func (*Map[K, V]) Len

func (m *Map[K, V]) Len() int

func (*Map[K, V]) NullItem

func (m *Map[K, V]) NullItem() Item[K, V]

func (*Map[K, V]) Set

func (m *Map[K, V]) Set(k K, v V) Item[K, V]

func (*Map[K, V]) Touch

func (m *Map[K, V]) Touch(item Item[K, V])

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL