lfu

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 5 Imported by: 0

README

LFU Algorithm

This LFU Algorithm implemented based on this paper: "An O(1) algorithm for implementing the LFU cache eviction scheme" (by Prof. Ketan Shah, Anirban Mitra, and Dhruv Matani)

Well, to be honest, it's not really exaclty as is like they wrote in the pseudocode. Because I need to change a few flow of the code due to the lack of Golang itself.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repository

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

Repository represent the data repository for inernal cache

func New

func New(maxSize, maxMemory uint64, expiryTreshold time.Duration) (repo *Repository)

New will initialize the LFU memory cache

func (*Repository) Clear

func (r *Repository) Clear() (err error)

Clear will clear up the item from cache

func (*Repository) Contains

func (r *Repository) Contains(key string) (ok bool)

Contains check if any item with the given key exist in the cache

func (*Repository) Delete

func (r *Repository) Delete(key string) (ok bool, err error)

Delete will delete the item from cache

func (*Repository) Get

func (r *Repository) Get(key string) (res *cache.Document, err error)

Get will retrieve the item from cache

func (*Repository) Keys

func (r *Repository) Keys() (keys []string, err error)

Keys return all keys from cache

func (*Repository) Len

func (r *Repository) Len() int

Len return the total items in the cache

func (*Repository) Set

func (r *Repository) Set(doc *cache.Document) (err error)

Set wil save the item to cache

Jump to

Keyboard shortcuts

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