Help us shape the future of Go! Take the 2026 Go Developer Survey

lru

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheNode

type CacheNode struct {
	Key, Value interface{}
}

type LRUCache

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

LRUCache is a simple thread-safe LRU cache. It uses a single RWMutex to guard both the list and the map to avoid deadlocks and inconsistent views.

func NewLRUCache

func NewLRUCache(cap int32) *LRUCache

func (*LRUCache) Get

func (lru *LRUCache) Get(k interface{}) (v interface{}, found bool, err error)

Get returns value, found flag and error. When key is found, it is moved to front as most recently used.

func (*LRUCache) Peek

func (lru *LRUCache) Peek(k interface{}) (v interface{}, found bool, err error)

Peek returns value, found flag and error without updating LRU order. It is useful for read-only inspection that should not affect eviction order.

func (*LRUCache) Remove

func (lru *LRUCache) Remove(k interface{}) bool

Remove deletes a key if it exists, and returns true when removed.

func (*LRUCache) Set

func (lru *LRUCache) Set(k, v interface{}) error

Set inserts or updates a key. If capacity is exceeded, the least recently used entry is evicted.

func (*LRUCache) Size

func (lru *LRUCache) Size() int

Jump to

Keyboard shortcuts

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