Categorygithub.com/hashicorp/golang-lru
modulepackage
0.6.0
Repository: https://github.com/hashicorp/golang-lru.git
Documentation: pkg.go.dev

# README

golang-lru

This provides the lru package which implements a fixed-size thread safe LRU cache. It is based on the cache in Groupcache.

Documentation

Full docs are available on Godoc

Example

Using the LRU is very simple:

l, _ := New(128)
for i := 0; i < 256; i++ {
    l.Add(i, nil)
}
if l.Len() != 128 {
    panic(fmt.Sprintf("bad len: %v", l.Len()))
}

# Packages

Package simplelru provides simple LRU implementation based on build-in container/list.

# Functions

New creates an LRU of the given size.
New2Q creates a new TwoQueueCache using the default values for the parameters.
New2QParams creates a new TwoQueueCache using the provided parameter values.
NewARC creates an ARC of the given size.
NewWithEvict constructs a fixed size cache with the given eviction callback.

# Constants

Default2QGhostEntries is the default ratio of ghost entries kept to track entries recently evicted.
Default2QRecentRatio is the ratio of the 2Q cache dedicated to recently added entries that have only been accessed once.
DefaultEvictedBufferSize defines the default buffer size to store evicted key/val.

# Structs

ARCCache is a thread-safe fixed size Adaptive Replacement Cache (ARC).
Cache is a thread-safe fixed size LRU cache.
TwoQueueCache is a thread-safe fixed size 2Q cache.