simplelfuda

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EvictCallback

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

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

type LFUDA

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

LFUDA is a non-threadsafe fixed size LFU with Dynamic Aging Cache

func NewGDSF added in v0.3.0

func NewGDSF(size float64, onEvict EvictCallback) *LFUDA

NewGDSF constructs an LFUDA of the given size in bytes and uses the GDSF eviction policy

func NewLFU added in v0.3.0

func NewLFU(size float64, onEvict EvictCallback) *LFUDA

NewLFU constructs an LFUDA of the given size in bytes and uses the LFU eviction policy

func NewLFUDA

func NewLFUDA(size float64, onEvict EvictCallback) *LFUDA

NewLFUDA constructs an LFUDA of the given size in bytes and uses the LFUDA eviction policy

func (*LFUDA) Age

func (l *LFUDA) Age() float64

Age returns the cache age factor

func (*LFUDA) Contains

func (l *LFUDA) 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 (*LFUDA) Get

func (l *LFUDA) Get(key interface{}) (interface{}, bool)

Get looks up a key's value from the cache

func (*LFUDA) Keys

func (l *LFUDA) Keys() []interface{}

Keys returns a slice of the keys in the cache ordered by frequency

func (*LFUDA) Len

func (l *LFUDA) Len() int

Len returns the number of items in the cache.

func (*LFUDA) Peek

func (l *LFUDA) Peek(key interface{}) (interface{}, bool)

Peek looks up a key's value from the cache but will not increment the items hit counter

func (*LFUDA) Purge

func (l *LFUDA) Purge()

Purge will completely clear the LFUDA cache

func (*LFUDA) Remove

func (l *LFUDA) Remove(key interface{}) bool

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

func (*LFUDA) Set

func (l *LFUDA) Set(key interface{}, value interface{}) bool

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

func (*LFUDA) Size added in v0.2.1

func (l *LFUDA) Size() float64

Size returns the number of items in the cache.

type LFUDACache

type LFUDACache interface {
	// Adds a value to the cache, returns true if an eviction occurred and
	// updates the "recently used"-ness of the key.
	Set(key, value interface{}) bool

	// Returns key's value from the cache and
	// updates the "recently used"-ness of the key. #value, isFound
	Get(key interface{}) (value interface{}, ok bool)

	// Checks if a key exists in cache without updating the recent-ness.
	Contains(key interface{}) (ok bool)

	// Returns key's value without updating the "recently used"-ness of the key.
	Peek(key interface{}) (value interface{}, ok bool)

	// Removes a key from the cache.
	Remove(key interface{}) bool

	// Returns a slice of the keys in the cache, from oldest to newest.
	Keys() []interface{}

	// Returns the number of items in the cache.
	Len() int

	// Returns the current size of the cache in bytes.
	Size() float64

	// Clears all cache entries.
	Purge()

	// Returns current age factor of the cache
	Age() float64
}

LFUDACache is the interface for simple LFUDA cache.

Jump to

Keyboard shortcuts

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