cache

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2022 License: LGPL-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 Entry

type Entry struct {
	Key, Value interface{}
}

Entry entry of cache.

type PrioCache

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

PrioCache a cache holds entries with priority. If len of cache reaches limit, the entry has lowest priority will be evicted.

func NewPrioCache

func NewPrioCache(limit int) *PrioCache

NewPrioCache create a new PrioCache.

func (*PrioCache) Contains

func (pc *PrioCache) Contains(key interface{}) bool

Contains returns whether the given key is contained.

func (*PrioCache) ForEach

func (pc *PrioCache) ForEach(cb func(*PrioEntry) bool) bool

ForEach iterates all cache entries.

func (*PrioCache) Get

func (pc *PrioCache) Get(key interface{}) (interface{}, float64, bool)

Get retrieves value for given key.

func (*PrioCache) Len

func (pc *PrioCache) Len() int

Len returns count of entries in the cache.

func (*PrioCache) Remove

func (pc *PrioCache) Remove(key interface{}) *PrioEntry

Remove removes the given key, and returns the removed entry if any.

func (*PrioCache) Set

func (pc *PrioCache) Set(key, value interface{}, priority float64)

Set set value and priority for given key.

type PrioEntry

type PrioEntry struct {
	Entry
	Priority float64
}

PrioEntry cache entry with priority.

type RandCache

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

RandCache a simple cache which randomly evicts entries when length exceeds limit.

func NewRandCache

func NewRandCache(limit int) *RandCache

NewRandCache create a new RandCache.

func (*RandCache) Contains

func (rc *RandCache) Contains(key interface{}) bool

Contains returns whether the given key is contained.

func (*RandCache) ForEach

func (rc *RandCache) ForEach(cb func(*Entry) bool) bool

ForEach iterates all entries in the cache.

func (*RandCache) Get

func (rc *RandCache) Get(key interface{}) (interface{}, bool)

Get get value for the given key.

func (*RandCache) Len

func (rc *RandCache) Len() int

Len returns count of entries in the cache.

func (*RandCache) Pick

func (rc *RandCache) Pick() *Entry

Pick pick an entry randomly.

func (*RandCache) Remove

func (rc *RandCache) Remove(key interface{}) bool

Remove removes key.

func (*RandCache) Set

func (rc *RandCache) Set(key, value interface{})

Set sets value for given key.

Jump to

Keyboard shortcuts

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