timed

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UnixTime

func UnixTime() int64

UnixTime is a ClockFunc that returns the current Unix time (seconds since the Unix epoch).

Types

type ClockFunc

type ClockFunc = func() int64

type LRU

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

LRU is a specialized open-addressing-hash-table-based implementation of a specialized LRU cache, using Copy-Update-Replace semantics to operate in a completely lock-less manner.

func NewLRU added in v1.11.2

func NewLRU(interval time.Duration, clock ClockFunc) *LRU

NewLRU initializes a new, empty LRU with the given interval and clock function. A warning will be logged if it is set below 1 second. Panics if the interval is more than math.MaxUint32 seconds, as this value cannot be used internally.

Note: timestamps are stored at second resolution, so the interval will be rounded down to the nearest second.

func (*LRU) Hit

func (m *LRU) Hit(key uint64) bool

Hit determines whether the given key should be kept or dropped based on the last time it was sampled. If the table grows larger than config.MaxItemCount, the [LRU.rebuild] method is called in a separate goroutine to begin the eviction process. Until this has completed, all updates to the LRU are effectively dropped, as they happen on the soon-to-be-replaced table.

Note: in order to run completely lock-less, LRU cannot store the 0 key in the table, as a 0 key is used as a sentinel value to identify free entries. To avoid this pitfall, [LRU.zeroKey] is used as a substitute for 0, meaning 0 and [LRU.zeroKey] are treated as the same key. This is not an issue in common use, as given a uniform distribution of keys this only happens 1 in 2^64-1 times.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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