lfu

package module
v1.0.0-test Latest Latest
Warning

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

Go to latest
Published: May 28, 2021 License: MIT Imports: 2 Imported by: 0

README

A simple LFU cache for golang. Based on the paper An O(1) algorithm for implementing the LFU cache eviction scheme.

Usage:

import "github.com/dgrijalva/lfu-go"

// Make a new thing
c := lfu.New()

// Set some values
c.Set("myKey", myValue)

// Retrieve some values
myValue = c.Get("myKey")

// Evict some values
c.Evict(1)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// If len > UpperBound, cache will automatically evict
	// down to LowerBound.  If either value is 0, this behavior
	// is disabled.
	UpperBound int
	LowerBound int

	EvictionChannel chan<- Eviction
	// contains filtered or unexported fields
}

func New

func New() *Cache

func (*Cache) Delete

func (c *Cache) Delete(key string)

func (*Cache) Evict

func (c *Cache) Evict(count int) int

func (*Cache) Get

func (c *Cache) Get(key string) interface{}

func (*Cache) Len

func (c *Cache) Len() int

func (*Cache) Set

func (c *Cache) Set(key string, value interface{})

type Eviction

type Eviction struct {
	Key   string
	Value interface{}
}

Jump to

Keyboard shortcuts

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