ttlmap

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 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] struct {
	// contains filtered or unexported fields
}

func New

func New[K comparable, V any](ttl time.Duration, numBuckets uint8) *Map[K, V]

Creates a map with expirable items.

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(key K) (value V, ok bool)

Looks up a key's value from the map.

func (*Map[K, V]) GetAndRemove

func (m *Map[K, V]) GetAndRemove(key K) (value V, ok bool)

Looks up a key's value from the map and removes it.

func (*Map[K, V]) Has

func (m *Map[K, V]) Has(key K) bool

func (*Map[K, V]) Put

func (m *Map[K, V]) Put(key K, value V)

Puts a value to the map.

func (*Map[K, V]) Remove

func (m *Map[K, V]) Remove(key K) bool

func (*Map[K, V]) Start

func (m *Map[K, V]) Start(ctx context.Context) (stop func())

Starts a cleanup loop.

func (*Map[K, V]) Update

func (m *Map[K, V]) Update(key K, cb func(value V) V) bool

Updates existing item or inserts a new one using provided callback function.

func (*Map[K, V]) Upsert

func (m *Map[K, V]) Upsert(key K, cb func(exists bool, value V) V)

Updates existing element or inserts a new one using provided callback function.

Jump to

Keyboard shortcuts

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