decaymap

package
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 2 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Zilch

func Zilch[T any]() T

Types

type Impl

type Impl[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Impl is a lazy key->value map. It's a wrapper around a map and a mutex. If values exceed their time-to-live, they are pruned at Get time.

func New

func New[K comparable, V any]() *Impl[K, V]

New creates a new DecayMap of key type K and value type V.

Key types must be comparable to work with maps.

func (*Impl[K, V]) Cleanup added in v1.16.0

func (m *Impl[K, V]) Cleanup()

Cleanup removes all expired entries from the DecayMap.

func (*Impl[K, V]) Close added in v1.23.0

func (m *Impl[K, V]) Close()

Close stops the background cleanup worker. It's optional to call; maps live for the process lifetime in many cases. Call in tests or when you know you no longer need the map to avoid goroutine leaks.

func (*Impl[K, V]) Delete added in v1.21.0

func (m *Impl[K, V]) Delete(key K) bool

Delete a value from the DecayMap by key.

If the value does not exist, return false. Return true after deletion.

func (*Impl[K, V]) Get

func (m *Impl[K, V]) Get(key K) (V, bool)

Get gets a value from the DecayMap by key.

If a value has expired, forcibly delete it if it was not updated.

func (*Impl[K, V]) Len added in v1.16.0

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

Len returns the number of entries in the DecayMap.

func (*Impl[K, V]) Set

func (m *Impl[K, V]) Set(key K, value V, ttl time.Duration)

Set sets a key value pair in the map.

Jump to

Keyboard shortcuts

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