lru

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Cache keeps recently used values. Safe for concurrent use by multiple goroutines.

func New

func New[K comparable, V any](capacity int) *Cache[K, V]

New returns a new empty cache that can hold up to capacity items.

func (*Cache[K, V]) Add

func (c *Cache[K, V]) Add(key K, value V)

Add adds key and value to the cache. If the cache is full, the oldest entry is removed. If key is already in the cache, value replaces the cached value.

func (*Cache[K, V]) Get

func (c *Cache[K, V]) Get(key K) (V, bool)

Get returns the value stored in the cache for a key, or zero value if no value is present. The ok result indicates whether value was found in the cache.

Jump to

Keyboard shortcuts

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