ttlmap

package module
v0.0.0-...-2f98bd0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2019 License: MIT Imports: 2 Imported by: 0

README

ttlmap Documentation

Concurrent map with expiring keys.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// The internal garbage collector interval.
	GcInterval = time.Second * 3
	// Now is used to retrieve the current local time.
	Now = time.Now
	// NewTicker is used to create new ticker.
	NewTicker = newTicker
)

Functions

This section is empty.

Types

type ExpiryFunc

type ExpiryFunc func(key interface{})

type Map

type Map struct {
	// contains filtered or unexported fields
}

Map is a concurrent map with expiring keys.

func NewMap

func NewMap(f ExpiryFunc) *Map

NewMap creates a new Map and starts the internal garbage collector. When f is not nil, it will be called on expired keys at the end of GC run.

func (*Map) Delete

func (m *Map) Delete(key interface{})

Delete deletes the value for a key.

func (*Map) Keys

func (m *Map) Keys() (ret []interface{})

Keys returns slice of map keys in no specified order.

func (*Map) Load

func (m *Map) Load(key interface{}) (value interface{}, ok bool)

Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.

func (*Map) Range

func (m *Map) Range(f func(key, value interface{}) bool)

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

func (*Map) Stop

func (m *Map) Stop()

Stop stops the internal garbage collector.

func (*Map) Store

func (m *Map) Store(key interface{}, value interface{}, ttl time.Duration)

Store sets the value for a key. The key expires after duration specified in ttl.

type Set

type Set struct {
	// contains filtered or unexported fields
}

func NewSet

func NewSet(f ExpiryFunc) *Set

NewSet creates a new Sap and starts the internal garbage collector. When f is not nil, it will be called on expired values at the end of GC run.

func (*Set) Contains

func (s *Set) Contains(value interface{}) bool

Contains checks if the value exists within the set.

func (*Set) Delete

func (s *Set) Delete(value interface{})

Delete removes the value from the set.

func (*Set) Insert

func (s *Set) Insert(value interface{}, ttl time.Duration)

Insert inserts the value into the set.

func (*Set) Stop

func (s *Set) Stop()

Stop stops the internal garbage collector.

func (*Set) Values

func (s *Set) Values() []interface{}

Values returns all set values in no specified order.

type Ticker

type Ticker interface {
	Tick() <-chan time.Time
	Stop()
}

Jump to

Keyboard shortcuts

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