lru

package
v2.8.3 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InvalidEntrySizeErrorMsg       = "size of the entry is more than the cache's maxSize"
	InvalidEntryErrorMsg           = "nil values are not supported"
	InvalidUpdateEntrySizeErrorMsg = "size of entry to be updated is not same as existing size"
	EntryNotExistErrMsg            = "entry with given key does not exist"
)

Predefined error messages returned by the Cache.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is a LRU cache for any lru.ValueType indexed by string keys. That means entry's value should be a lru.ValueType.

func NewCache

func NewCache(maxSize uint64) *Cache

NewCache returns the reference of cache object by initialising the cache with the supplied maxSize, which must be greater than zero.

func (*Cache) Erase

func (c *Cache) Erase(key string) (value ValueType)

Erase any entry for the supplied key, also returns the value of erased key.

func (*Cache) Insert

func (c *Cache) Insert(
	key string,
	value ValueType) ([]ValueType, error)

Insert the supplied value into the cache, overwriting any previous entry for the given key. The value must be non-nil. Also returns a slice of ValueType evicted by the new inserted entry.

func (*Cache) LookUp

func (c *Cache) LookUp(key string) (value ValueType)

LookUp a previously-inserted value for the given key. Return nil if no value is present.

func (*Cache) LookUpWithoutChangingOrder

func (c *Cache) LookUpWithoutChangingOrder(key string) (value ValueType)

LookUpWithoutChangingOrder looks up previously-inserted value for a given key without changing the order of entries in the cache. Return nil if no value is present.

Note: Because this look up doesn't change the order, it only acquires and releases read lock.

func (*Cache) UpdateWithoutChangingOrder

func (c *Cache) UpdateWithoutChangingOrder(
	key string,
	value ValueType) error

UpdateWithoutChangingOrder updates entry with the given key in cache with given value without changing order of entries in cache, returning error if an entry with given key doesn't exist. Also, the size of value for entry shouldn't be updated with this method (use c.Insert for updating size).

type ValueType

type ValueType interface {
	Size() uint64
}

Jump to

Keyboard shortcuts

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