s4lru

package module
v0.0.0-...-fd9b33c Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2015 License: MIT Imports: 1 Imported by: 2

README

s4lru -- an implementation of Quadruply-segmented LRU cache

Godoc: http://godoc.org/github.com/dgryski/go-s4lru

Documentation

Overview

Package s4lru implements the 4-segmented LRU caching algorithm

From http://www.cs.cornell.edu/~qhuang/papers/sosp_fbanalysis.pdf

Four queues are maintained at levels 0 to 3. On a cache miss, the item is
inserted at the head of queue 0. On a cache hit, the item is moved to the
head of the next higher queue (items in queue 3 move to the head of queue
3).  Each queue is allocated 1/4 of the total cache size and items are
evicted from the tail of a queue to the head of the next lower queue to
maintain the size invariants. Items evicted from queue 0 are evicted from
the cache

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is an LRU cache. It is not safe for concurrent access.

func New

func New(capacity int) *Cache

New returns a new S4LRU cache that with the given capacity. Each of the lists will have 1/4 of the capacity. New will panic if the capacity is not evenly divisible by 4.

func (*Cache) Get

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

Get returns a value from the cache

func (*Cache) Len

func (c *Cache) Len() int

Len returns the total number of items in the cache

func (*Cache) Remove

func (c *Cache) Remove(key string) (interface{}, bool)

Remove removes an item from the cache, returning the item and a boolean indicating if it was found

func (*Cache) Set

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

Set sets a value in the cache

Jump to

Keyboard shortcuts

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