package lru

import "cuelang.org/go/internal/golangorgx/gopls/util/lru"

The lru package implements a fixed-size in-memory LRU cache.

Index

Types

type Cache

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

A Cache is a fixed-size in-memory LRU cache.

func New

func New(capacity int) *Cache

New creates a new Cache with the given capacity, which must be positive.

The cache capacity uses arbitrary units, which are specified during the Set operation.

func (*Cache) Get

func (c *Cache) Get(key any) any

Get retrieves the value for the specified key, or nil if the key is not found.

If the key is found, its access time is updated.

func (*Cache) Set

func (c *Cache) Set(key, value any, size int)

Set stores a value for the specified key, using its given size to update the current cache size, evicting old entries as necessary to fit in the cache capacity.

Size must be a non-negative value. If size is larger than the cache capacity, the value is not stored and the cache is not modified.

Source Files

lru.go

Version
v0.12.0 (latest)
Published
Jan 30, 2025
Platform
linux/amd64
Imports
3 packages
Last checked
8 hours ago

Tools for package owners.