lrucache

package
v1.96.0-cluster Latest Latest
Warning

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

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

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.

Call NewCache() for creating new Cache.

func NewCache

func NewCache(getMaxSizeBytes func() int) *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.

func (*Cache) MustStop

func (c *Cache) MustStop()

MustStop frees up resources occupied by c.

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.

func (*Cache) SizeBytes

func (c *Cache) SizeBytes() int

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

func (*Cache) SizeMaxBytes

func (c *Cache) SizeMaxBytes() int

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() int
}

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