lru

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2018 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package lru implements a Least Recently Used cache.

This implmenetation lets you set the limitations of the cache size based upon a number of entries.

The package also includes a utility called "tailor" for tailoring the cache to a specific key/value type instead of interface{}, allowing you to remove the overhead of runtime type inference.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Get returns the value stored at key "k" and true if found. O(1) operation.
	Get(k interface{}) (interface{}, bool)

	// Set adds a value at key "k" of value "v". O(1) operation.
	Set(k interface{}, v interface{}) error

	// Remove removes a value at key "k". O(1) operation.
	Remove(k interface{})

	// RemoveOldest removes the oldest value in the cache. O(1) operation.
	RemoveOldest()

	// Len returns the current length of the cache.
	Len() int
}

Cache provides the LRU cache.

func New

func New(options ...Option) (Cache, error)

New is the constructor for Cache. Must pass either NumberLimit or MemoryLimit, but not both.

type Option

type Option func(c *cache)

Option is an optional argument for New().

func NumberLimit

func NumberLimit(i int) Option

NumberLimit sets a limit to the number of items that can be stored in the Cache before an insertion purges an existing item.

func PreSize

func PreSize(i uint64) Option

PreSize pre-sizes the internal data structures to hold "i" items. Similar to make(map[key]value, i).

Directories

Path Synopsis
tailor is a very simplistic program for replacing the key and value types in lru.go with concrete types that do not require any type of runtime reflection.
tailor is a very simplistic program for replacing the key and value types in lru.go with concrete types that do not require any type of runtime reflection.

Jump to

Keyboard shortcuts

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