cachelruany

package
v0.0.0-...-8084858 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCaches

func NewCaches(cacheConfigurations ...CfgCache) map[string]*CacheLRU

NewCachesForMethods is a constructor for the map holding the caches.

Types

type CacheLRU

type CacheLRU struct {
	Queue *list.List
	Cache map[any]*Item // key would be the type used in correspondent method
	// contains filtered or unexported fields
}

CacheLRU acts as LRU caching based on the capacity and the cache. The queue is the double linked list from which the LRU element is deleted as needed. The cache key should be a hasheable type.

func NewCacheLRU

func NewCacheLRU(capacity uint16) *CacheLRU

func (*CacheLRU) Delete

func (c *CacheLRU) Delete(key any) error

func (*CacheLRU) Get

func (c *CacheLRU) Get(key any) (any, error)

Get fetches an element from cache if it finds it by the passed key.

func (*CacheLRU) Put

func (c *CacheLRU) Put(key, value any)

Put places a key value in the cache and linked list. The LRU element is replaced by the added element if the capacity is reached.

func (*CacheLRU) String

func (c *CacheLRU) String() string

Stringer added for debugging.

type CfgCache

type CfgCache struct {
	Name     string
	Capacity uint16
}

CfgCache consolidates the cache capacity and key based on which it can be retrieved.

type Item

type Item struct {
	KeyPtr  *list.Element
	Payload any
}

Item points to a corresponding element in the doubly linked list.

Jump to

Keyboard shortcuts

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