lru

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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.

Jump to

Keyboard shortcuts

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