lfu

package
v0.30.0 Latest Latest
Warning

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

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

Documentation

Overview

nolint:forcetypeassert

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LFU

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

LFU is a thread-safe fixed size LFU cache.

func New

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

func (*LFU[K, V]) Add

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

Add adds a value to the cache.

func (*LFU[K, V]) Close

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

Close closes the cache and unregisters the metrics.

func (*LFU[K, V]) Evict

func (c *LFU[K, V]) Evict()

Evict one element from the cache depending on the eviction policy.

func (*LFU[K, V]) Get

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

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

func (*LFU[K, V]) Peek

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

Peek looks up a key's value from the cache without updating the frequency.

func (*LFU[K, V]) Purge

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

Purge is used to completely clear the cache.

func (*LFU[K, V]) Remove

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

Remove removes the provided key from the cache.

func (*LFU[K, V]) RemoveMatching

func (c *LFU[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(lfu *LFU[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