Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
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
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 ¶
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.