timap

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: MIT Imports: 4 Imported by: 1

README

Timap

Report Card GoCover

Different map implementations

  • Timap is a wrapper over sync.Map that allows to set life time for each key-value pair.
  • CtxMap allows storing key/value pairs with context to be deleted once the context is cancelled or its deadline is exceeded.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CtxMap added in v1.1.0

type CtxMap interface {
	Load(key interface{}) (value interface{}, ok bool)
	Store(ctx context.Context, key, value interface{}, callbacks ...func())
	Delete(key interface{})
	Range(f func(key, value interface{}) bool)
}

CtxMap stores provided key/value pairs with context.

func NewCtxMap added in v1.1.0

func NewCtxMap() CtxMap

NewCtxMap create a new map that stores key/value pairs with provided context. The pair is available until parent context is cancelled, or its deadline exceeds.

type Timap

type Timap interface {
	Load(key interface{}) (value interface{}, ok bool)
	Store(key, value interface{}, lifeTime ...time.Duration)
	Delete(key interface{})
	Range(f func(key, value interface{}) bool)
}

Timap represents "time map", it is a wrapper over sync.Map that allows to store key-value pairs for certain period of time. Default duration can be defined for all key-value pairs in the constructor func, but it is also possible to define custom life time for each pair separately. Watcher will create a goroutine for every temporrary pair. Try not to use it with huge maps.

func New

func New(lifeTime time.Duration) Timap

New is a Timap constructor func. If lifeTime == 0 key-value pairs will not have any time limits (by default), values still can be deleted by calling Delete().

Jump to

Keyboard shortcuts

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