expiringmap

package
v1.0.51 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2024 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExpiringMap

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

ExpiringMap is a map that expires items after a given duration. It uses go generics to allow for any type of key and value, although the key must be comparable. The map is safe for concurrent use.

func New

func New[K comparable, V any](expire time.Duration) *ExpiringMap[K, V]

func (*ExpiringMap[K, V]) Clear

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

Clear clears the map.

func (*ExpiringMap[K, V]) Delete

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

Delete deletes the given key from the map.

func (*ExpiringMap[K, V]) Get

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

Get returns the value for the given key.

func (*ExpiringMap[K, V]) Items

func (m *ExpiringMap[K, V]) Items() map[K]V

Items returns a copy of the items in the map.

func (*ExpiringMap[K, V]) IterateWithFn added in v1.0.20

func (m *ExpiringMap[K, V]) IterateWithFn(fn func(K, V) bool, stopCh ...chan bool)

Iterate iterates over the map and calls the given function for each item. If the function returns false, the iteration stops. If write is true, the map is locked for writing, otherwise it is locked for reading.

func (*ExpiringMap[K, V]) Len

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

Len returns the number of items in the map.

func (*ExpiringMap[K, V]) Set

func (m *ExpiringMap[K, V]) Set(key K, value V)

Set sets the value for the given key.

func (*ExpiringMap[K, V]) WithEvictionChannel added in v1.0.17

func (m *ExpiringMap[K, V]) WithEvictionChannel(ch chan []V) *ExpiringMap[K, V]

func (*ExpiringMap[K, V]) WithEvictionFunction added in v1.0.17

func (m *ExpiringMap[K, V]) WithEvictionFunction(f func(K, V) bool) *ExpiringMap[K, V]

Jump to

Keyboard shortcuts

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