lrucache

package
v1.0.115 Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LRUCache

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

LRUCache implements a Least Recently Used eviction cache

func NewCache

func NewCache(size int) (*LRUCache, error)

NewCache creates a new LRU cache instance

func (*LRUCache) Clear

func (c *LRUCache) Clear()

Clear is used to completely clear the cache.

func (*LRUCache) Get

func (c *LRUCache) Get(key []byte) (value interface{}, ok bool)

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

func (*LRUCache) Has

func (c *LRUCache) Has(key []byte) bool

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

func (*LRUCache) HasOrAdd

func (c *LRUCache) HasOrAdd(key []byte, value interface{}) (found, evicted bool)

HasOrAdd 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 (*LRUCache) IsInterfaceNil

func (c *LRUCache) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

func (*LRUCache) Keys

func (c *LRUCache) Keys() [][]byte

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

func (*LRUCache) Len

func (c *LRUCache) Len() int

Len returns the number of items in the cache.

func (*LRUCache) MaxSize

func (c *LRUCache) MaxSize() int

MaxSize returns the maximum number of items which can be stored in cache.

func (*LRUCache) Peek

func (c *LRUCache) Peek(key []byte) (value interface{}, ok bool)

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

func (*LRUCache) Put

func (c *LRUCache) Put(key []byte, value interface{}) (evicted bool)

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

func (*LRUCache) RegisterHandler

func (c *LRUCache) RegisterHandler(handler func(key []byte, value interface{}))

RegisterHandler registers a new handler to be called when a new data is added

func (*LRUCache) Remove

func (c *LRUCache) Remove(key []byte)

Remove removes the provided key from the cache.

func (*LRUCache) RemoveOldest

func (c *LRUCache) RemoveOldest()

RemoveOldest removes the oldest item from the cache.

Jump to

Keyboard shortcuts

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