lru

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LRU

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

func New

func New[K comparable, V any](reg prometheus.Registerer, opts ...Option[K, V]) *LRU[K, V]

New returns a new cache with the provided maximum items count.

func (*LRU[K, V]) Add

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

Add adds a value to the cache.

func (*LRU[K, V]) Close

func (c *LRU[K, V]) Close() error

Close closes the cache using registered closer.

func (*LRU[K, V]) Get

func (c *LRU[K, V]) Get(key K) (value V, ok bool)

Get looks up a key's value from the cache.

func (*LRU[K, V]) Peek

func (c *LRU[K, V]) Peek(key K) (value V, ok bool)

Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.

func (*LRU[K, V]) Purge

func (c *LRU[K, V]) Purge()

Purge is used to completely clear the cache.

func (*LRU[K, V]) Remove

func (c *LRU[K, V]) Remove(key K)

Remove removes the provided key from the cache.

func (*LRU[K, V]) RemoveMatching

func (c *LRU[K, V]) RemoveMatching(predicate func(key K, value V) bool)

removeMatching removes items from the cache that match the predicate.

type Option

type Option[K comparable, V any] func(lru *LRU[K, V])

func WithMaxSize

func WithMaxSize[K comparable, V any](maxSize int) Option[K, V]

func WithOnAdded

func WithOnAdded[K comparable, V any](onAdded func(key K, value V)) Option[K, V]

func WithOnEvict

func WithOnEvict[K comparable, V any](onEvict func(key K, value V)) Option[K, V]

Jump to

Keyboard shortcuts

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