cache

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LRU_ITEM_TO_REMOVE_GETTER = func(currentSet *list.List) *list.Element {
		return currentSet.Back()
	}

	MRU_ITEM_TO_REMOVE_GETTER = func(currentSet *list.List) *list.Element {
		return currentSet.Front()
	}
)

Functions

This section is empty.

Types

type Cache

type Cache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Cache structure to be used for handling the cache data

func NewCache

func NewCache[K comparable, V any](setSize int, replacementAlgorithm ...ReplacementAlgo) (*Cache[K, V], error)

NewCache returns a new instance of Cache. It saves the provided setSize in the returned instance

func (*Cache[K, V]) Delete

func (c *Cache[K, V]) Delete(key K)

Delete removes the item associated to the provided key if it's found.

func (*Cache[K, V]) Get

func (c *Cache[K, V]) Get(key K) (V, bool)

Get returns the item if it's present in cache and a true flag. Otherwise it returns false and an empty value

func (*Cache[K, V]) ListAll

func (c *Cache[K, V]) ListAll() map[K]V

ListAll returns all element saved in cache

func (*Cache[K, V]) Put

func (c *Cache[K, V]) Put(key K, value V)

Put implements functionality that seet a new value in the cache, following n-way-set-associative-cache

type ReplacementAlgo

type ReplacementAlgo string
const (
	LRU_ALGO ReplacementAlgo = "LRU"
	MRU_ALGO ReplacementAlgo = "MRU"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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