wlru

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2021 License: MIT Imports: 2 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 is a thread-safe fixed size LRU cache.

func New

func New(maxWeight uint, maxSize int) (*Cache, error)

New creates a weighted LRU of the given size.

func NewWithEvict

func NewWithEvict(maxWeight uint, maxSize int, onEvicted func(key interface{}, value interface{})) (*Cache, error)

NewWithEvict constructs a fixed weight/size cache with the given eviction callback.

func (*Cache) Add

func (c *Cache) Add(key, value interface{}, weight uint) (evicted int)

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

func (*Cache) Contains

func (c *Cache) Contains(key interface{}) bool

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

func (*Cache) ContainsOrAdd

func (c *Cache) ContainsOrAdd(key, value interface{}, weight uint) (ok bool, evicted int)

ContainsOrAdd checks if a key is in the cache without updating the recent-ness or deleting it for being stale, and if not, adds the value. Returns whether found and whether an eviction occurred.

func (*Cache) Get

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

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

func (*Cache) GetOldest

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

GetOldest returns the oldest entry

func (*Cache) Keys

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

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

func (*Cache) Len

func (c *Cache) Len() int

Len returns the number of items in the cache.

func (*Cache) Peek

func (c *Cache) 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 (*Cache) PeekOrAdd

func (c *Cache) PeekOrAdd(key, value interface{}, weight uint) (previous interface{}, ok bool, evicted int)

PeekOrAdd checks if a key is in the cache without updating the recent-ness or deleting it for being stale, and if not, adds the value. Returns whether found and whether an eviction occurred.

func (*Cache) Purge

func (c *Cache) Purge()

Purge is used to completely clear the cache.

func (*Cache) Remove

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

Remove removes the provided key from the cache.

func (*Cache) RemoveOldest

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

RemoveOldest removes the oldest item from the cache.

func (*Cache) Resize

func (c *Cache) Resize(maxWeight uint, maxSize int) (evicted int)

Resize changes the cache size.

func (*Cache) Total

func (c *Cache) Total() (weight uint, num int)

Total returns the total weight and number of items in the cache.

func (*Cache) Weight

func (c *Cache) Weight() uint

Weight returns the total weight of items in the cache.

Jump to

Keyboard shortcuts

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