lrucache

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DropValueCallback

type DropValueCallback func(key string, val interface{})

type LRUCache

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

LRUCache is a fixed-size cache of key/value pairs. The lookup map is used to access values by their key. The LRU doubly-linked list is used to track entries from the least-recently used (the head) to the most recently used (the tail). An optional callback notifies the application when a value is dropped so it can be destroyed.

func NewLRUCache

func NewLRUCache(size int, dropVal DropValueCallback) *LRUCache

NewLRUCache creates an LRU cache of a given size. An optional callback is invoked when a value is dropped from the cache, either overwritten or evicted.

func (*LRUCache) Get

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

Get looks up the value in the cache for a given key. If found, it returns (value, true). Otherwise it returns (nil, false).

func (*LRUCache) Put

func (c *LRUCache) Put(key string, val interface{})

Put stores a key/value pair into the cache. The ownership of the value object is transferred to the cache, the application should not modify or reuse that object.

Jump to

Keyboard shortcuts

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