simplewlru

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2022 License: MIT Imports: 2 Imported by: 0

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 implements a non-thread safe fixed size/weight 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, onEvict EvictCallback) (*Cache, error)

NewWeightedLRU constructs an LRU of the given weight and size

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{}) (ok bool)

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

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) 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, returning if the key was contained.

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.

type EvictCallback

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

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

Jump to

Keyboard shortcuts

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