ttlmap

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

type Map[K comparable, V any] = sharder[K, Shard[K, V]]

Map is a sharded map with sharded locks with automatic, amortised cleanup based on item expiry times. Should be pretty efficient and low drama

func New

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

func NewWithOpts

func NewWithOpts[K comparable, V any](opts Opts) *Map[K, V]

type Opts

type Opts struct {
	// Number of internal map shards. Must be power of 2. Defaults to 32.
	Shards int
}

type Shard

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

func (*Shard[K, V]) Delete

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

Delete must be called while Lock is held

func (*Shard[K, V]) Get

func (m *Shard[K, V]) Get(key K) (v V, expiresAt time.Time, ok bool)

Get must be called while Lock is held

func (*Shard[K, V]) GetValue

func (m *Shard[K, V]) GetValue(key K) (v V, ok bool)

func (*Shard[K, V]) Lock

func (m *Shard[K, V]) Lock()

func (*Shard[K, V]) Set

func (m *Shard[K, V]) Set(key K, value V, expiresAt time.Time)

Set must be called while Lock is held

func (*Shard[K, V]) SetNow

func (m *Shard[K, V]) SetNow(now *time.Time)

SetNow allows defining "now" time on a shard. Only intended for use when testing. When nil, uses time.Now()

func (*Shard[K, V]) Unlock

func (m *Shard[K, V]) Unlock()

Jump to

Keyboard shortcuts

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