lru

package
v1.1.4 Latest Latest
Warning

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

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

Documentation

Overview

Package lru implements a constant time, generic LRU cache.

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 exposes an interface for an LRU cache.

func New

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

New returns a new cache with the given capacity.

func (*Cache[K, V]) Delete

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

Delete the given key from the cache.

func (*Cache[K, V]) ForEach

func (c *Cache[K, V]) ForEach(fn func(key K, value V) error) error

ForEach runs the given function for each key/value pair in the cache, iteration takes place with most used first.

func (*Cache[K, V]) Get

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

Get returns the value for the given key if it exists in the cache.

func (*Cache[K, V]) Has

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

Has returns a boolean indicating whether the cache contains the given key.

func (*Cache[K, V]) Set

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

Set the value for the given key, returns a boolean indicating whether the key was already in the cache.

Jump to

Keyboard shortcuts

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