lfu

package module
Version: v0.0.0-...-f174e76 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2014 License: MIT Imports: 2 Imported by: 2

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) 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{}
}

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL