lrucache

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: MIT Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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