lru

package
v1.12.2 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EvictCallback added in v1.10.5

type EvictCallback func(key interface{}, value interface{})

EvictCallback is used to get a callback when a cache entry is evicted

type LRU added in v1.10.5

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

LRU implements a non-thread safe fixed size LRU cache

func New

func New(size int, onEvict EvictCallback) *LRU

NewLRU constructs an LRU of the given size

func (*LRU) Add added in v1.10.5

func (c *LRU) Add(key, value interface{}) (evicted bool)

Add adds a value to the cache. Returns true if an eviction occurred.

func (*LRU) Contains added in v1.10.5

func (c *LRU) Contains(key interface{}) (ok bool)

Contains checks if a key is in the cache, without updating the recent-ness or deleting it for being stale.

func (*LRU) Get added in v1.10.5

func (c *LRU) Get(key interface{}) (value interface{}, ok bool)

Get looks up a key's value from the cache.

func (*LRU) GetOldest added in v1.10.5

func (c *LRU) GetOldest() (key, value interface{}, ok bool)

GetOldest returns the oldest entry

func (*LRU) Keys added in v1.10.5

func (c *LRU) Keys() []interface{}

Keys returns a slice of the keys in the cache, from oldest to newest.

func (*LRU) Len added in v1.10.5

func (c *LRU) Len() int

Len returns the number of items in the cache.

func (*LRU) Peek added in v1.10.5

func (c *LRU) Peek(key interface{}) (value interface{}, ok bool)

Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.

func (*LRU) Purge added in v1.10.5

func (c *LRU) Purge()

Purge is used to completely clear the cache.

func (*LRU) Remove added in v1.10.5

func (c *LRU) Remove(key interface{}) (present bool)

Remove removes the provided key from the cache, returning if the key was contained.

func (*LRU) RemoveOldest added in v1.10.5

func (c *LRU) RemoveOldest() (key, value interface{}, ok bool)

RemoveOldest removes the oldest item from the cache.

func (*LRU) Resize added in v1.10.5

func (c *LRU) Resize(size int) (evicted int)

Resize changes the cache size.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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