lrucache

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lrucache is the bounded, sharded LRU of the answers of one segment of the resolver, with a time to live for members and one for non members, and a version token that turns the entries of an older version into misses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is a bounded LRU of the answers of one segment, with a TTL for members and one for non members.

func New

func New(cfg Config) *Cache

New returns an empty cache. MaxEntries and Shards must be positive.

func (*Cache) Clear

func (c *Cache) Clear()

Clear drops every entry.

func (*Cache) Current

func (c *Cache) Current() string

Current returns the version token, empty when none was learned. It does not allocate.

func (*Cache) Generation

func (c *Cache) Generation() uint64

Generation is the generation of the version token: it grows on every change of the token.

func (*Cache) Get

func (c *Cache) Get(key string, now time.Time) (segment.State, bool)

Get returns the cached answer of key at the instant now. It does not allocate.

func (*Cache) Len

func (c *Cache) Len() int

Len is the number of entries held, expired ones included until they are read.

func (*Cache) Put

func (c *Cache) Put(key string, state segment.State, now time.Time)

Put caches a Member or a NotMember answer. It ignores any other state.

func (*Cache) SetVersion

func (c *Cache) SetVersion(token string) bool

SetVersion starts a new generation when the token differs from the current one: the entries of every earlier generation become misses, without being touched, and age out of the LRU. A token that comes back is a new generation too, so its old entries never revive. It reports whether the token changed.

type Config

type Config struct {
	// MaxEntries bounds the entries of the whole cache.
	MaxEntries int
	// Shards is the number of locks.
	Shards int
	// TTL is how long a Member is kept.
	TTL time.Duration
	// NegativeTTL is how long a NotMember is kept.
	NegativeTTL time.Duration
}

Config is the size and the lifetimes of a cache.

Jump to

Keyboard shortcuts

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