lru

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCapacity

func WithCapacity[K comparable, V any](capacity uint) func(*LRU[K, V])

func WithExpireTimeout

func WithExpireTimeout[K comparable, V any](t time.Duration) func(*LRU[K, V])

func WithOnRemove

func WithOnRemove[K comparable, V any](f func(K, V)) func(*LRU[K, V])

Types

type AddOption

type AddOption func(*addOptions)

func WithExpireTimeUnix

func WithExpireTimeUnix(t time.Time) AddOption

type LRU

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

LRU Least Recently Used

func New added in v0.3.5

func New[K comparable, V any](options ...Option[K, V]) *LRU[K, V]

New create new lru cache

func (*LRU[K, V]) Add

func (l *LRU[K, V]) Add(key K, value V, opts ...AddOption)

func (*LRU[K, V]) Delete

func (l *LRU[K, V]) Delete(key K)

Delete delete a key from cache

func (*LRU[K, V]) LastPopValue

func (l *LRU[K, V]) LastPopValue() (v V, _ bool)

func (*LRU[K, V]) Load

func (l *LRU[K, V]) Load(key K) (v V, ok bool)

func (*LRU[K, V]) LoadExpireTime

func (l *LRU[K, V]) LoadExpireTime(key K) (v V, expireTime time.Time, ok bool)

func (*LRU[K, V]) Range

func (l *LRU[K, V]) Range(ranger func(K, V))

func (*LRU[K, V]) ReverseLoad

func (l *LRU[K, V]) ReverseLoad(v V) (k K, ok bool)

func (*LRU[K, V]) ValueExist

func (l *LRU[K, V]) ValueExist(key V) bool

type Option

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

Jump to

Keyboard shortcuts

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