decaymap

package
v1.26.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: CC0-1.0 Imports: 2 Imported by: 0

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

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

Cleanup removes all expired entries from the DecayMap.

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

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