lrucache

package
v1.139.0-cluster Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: Apache-2.0 Imports: 6 Imported by: 4

Documentation

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 caches Entry entries.

If the cache is full the least recently used entries are evicted to make room for new entries. Additionally, entries are evicted if not retrieved within the last three minutes.

The cache should be used only if the rate of requests is in the range of thousands. I.e. it is suitable for use in data retrieval paths and should not be used in data ingestion path since its qps is often in the range of millions.

Call NewCache() for creating new Cache.

func NewCache

func NewCache(getMaxSizeBytes func() uint64) *Cache

NewCache creates new cache.

Cache size in bytes is limited by the value returned by getMaxSizeBytes() callback. Call MustStop() in order to free up resources occupied by Cache.

func (*Cache) GetEntry

func (c *Cache) GetEntry(k string) Entry

GetEntry returns an Entry for the given key k from c.

func (*Cache) Len

func (c *Cache) Len() int

Len returns the number of blocks in the cache c.

func (*Cache) Misses

func (c *Cache) Misses() uint64

Misses returns the number of cache misses for c since cache creation or last reset.

func (*Cache) MustStop

func (c *Cache) MustStop()

MustStop frees up resources occupied by cache.

func (*Cache) PutEntry

func (c *Cache) PutEntry(k string, e Entry)

PutEntry puts the given Entry e under the given key k into c.

func (*Cache) Requests

func (c *Cache) Requests() uint64

Requests returns the number of requests served by c since cache creation or last reset.

func (*Cache) Reset added in v1.110.25

func (c *Cache) Reset()

Reset resets the cache.

func (*Cache) Resets added in v1.110.25

func (c *Cache) Resets() uint64

Resets returns the number of cache resets since its creation.

func (*Cache) SizeBytes

func (c *Cache) SizeBytes() uint64

SizeBytes returns an approximate size in bytes of all the blocks stored in the cache c.

func (*Cache) SizeMaxBytes

func (c *Cache) SizeMaxBytes() uint64

SizeMaxBytes returns the max allowed size in bytes for c.

type Entry

type Entry interface {
	// SizeBytes must return the approximate size of the given entry in bytes
	SizeBytes() uint64
}

Entry is an item, which may be cached in the Cache.

Jump to

Keyboard shortcuts

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