fifocache

package
v1.0.100 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2020 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FIFOShardedCache

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

FIFOShardedCache implements a First In First Out eviction cache

func NewShardedCache

func NewShardedCache(size int, shards int) (*FIFOShardedCache, error)

NewShardedCache creates a new cache instance

func (*FIFOShardedCache) Clear

func (c *FIFOShardedCache) Clear()

Clear is used to completely clear the cache.

func (*FIFOShardedCache) Get

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

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

func (*FIFOShardedCache) Has

func (c *FIFOShardedCache) 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 (*FIFOShardedCache) HasOrAdd

func (c *FIFOShardedCache) 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 (*FIFOShardedCache) IsInterfaceNil

func (c *FIFOShardedCache) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

func (*FIFOShardedCache) Keys

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

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

func (*FIFOShardedCache) Len

func (c *FIFOShardedCache) Len() int

Len returns the number of items in the cache.

func (*FIFOShardedCache) MaxSize

func (c *FIFOShardedCache) MaxSize() int

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

func (*FIFOShardedCache) Peek

func (c *FIFOShardedCache) 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 (*FIFOShardedCache) Put

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

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

func (*FIFOShardedCache) RegisterHandler

func (c *FIFOShardedCache) RegisterHandler(handler func(key []byte))

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

func (*FIFOShardedCache) Remove

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

Remove removes the provided key from the cache.

func (*FIFOShardedCache) RemoveOldest

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