cache_policy

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyPair

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

KeyPair: the list node containing both block key and cache block values

type LRUCache

type LRUCache struct {
	sync.RWMutex
	Capacity int64
	List     *list.List              //DoublyLinkedList: node1->node2.... node:=KeyPair
	Elements map[int64]*list.Element //blockKey:KeyPair
	Occupied int64
}

LRUCache definition for Least Recently Used Cache implementation

func NewLRUCache

func NewLRUCache(capacity int64) *LRUCache

NewLRUCache: creates a new LRUCache object with the defined capacity

func (*LRUCache) Get

func (cache *LRUCache) Get(bk int64) (*common.Block, bool)

Get: returns the cache value stored for the key, cache hits the handle and moves the list pointer to front of the list

func (*LRUCache) Keys

func (cache *LRUCache) Keys() []int64

Keys: returns all the keys present in LRUCache

func (*LRUCache) LeastRecentlyUsed

func (cache *LRUCache) LeastRecentlyUsed() *common.Block

func (*LRUCache) Print

func (cache *LRUCache) Print()

func (*LRUCache) Purge

func (cache *LRUCache) Purge()

Purge: clears LRUCache

func (*LRUCache) Put

func (cache *LRUCache) Put(key int64, value *common.Block) bool

Put: Inserts the key,value pair in LRUCache. Return false if failed.

func (*LRUCache) RecentlyUsed

func (cache *LRUCache) RecentlyUsed() *common.Block

func (*LRUCache) Remove

func (cache *LRUCache) Remove(key int64)

Remove: removes the entry for the respective key

func (*LRUCache) Resize

func (cache *LRUCache) Resize(bk, newEndIndex int64) bool

Resize: resizes a cached block and adjusts occupied size

Jump to

Keyboard shortcuts

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