expire

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CachedClock

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

CachedClock is a clock that is only updated on demand. Until the Update method is not invoked, the Time method will return always the same value. Its main purpose is to avoid too many time.Now syscalls in scenarios with thousands of processed flows per second.

func NewCachedClock

func NewCachedClock(baseClock func() time.Time) *CachedClock

func (*CachedClock) Time

func (ex *CachedClock) Time() time.Time

Time returns the time returned by the base clock the last time that the Update method was invoked.

func (*CachedClock) Update

func (ex *CachedClock) Update()

Update the CachedClock time according to its base clock.

type Clock

type Clock func() time.Time

type ExpiryMap

type ExpiryMap[T any] struct {
	// contains filtered or unexported fields
}

ExpiryMap stores elements in a synchronized map, and removes them if they haven't been accessed/updated for a given time period TODO: optimize to minimize memory generation

func NewExpiryMap

func NewExpiryMap[T any](clock Clock, ttl time.Duration) *ExpiryMap[T]

NewExpiryMap creates an expiry map given a Clock implementation and a TTL. Its labeled instances are dropped if they haven't been updated during the last timeout period

func (*ExpiryMap[T]) All

func (ex *ExpiryMap[T]) All() []T

All returns an array with all the stored entries. It might contain expired entries if DeleteExpired is not invoked before it. TODO: use https://tip.golang.org/wiki/RangefuncExperiment when available

func (*ExpiryMap[T]) DeleteAll

func (ex *ExpiryMap[T]) DeleteAll() []T

DeleteAll cleans the map and returns a slice with its deleted elements

func (*ExpiryMap[T]) DeleteExpired

func (ex *ExpiryMap[T]) DeleteExpired() []T

DeleteExpired entries and return their label set

func (*ExpiryMap[T]) GetOrCreate

func (ex *ExpiryMap[T]) GetOrCreate(lbls []string, instancer func() T) T

GetOrCreate returns the stored object for the given slice of label values. If that combination of label values is accessed for the first time, a new instance is created. If not, a cached copy is returned and the "last access" cache time is updated.

Jump to

Keyboard shortcuts

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