lru

package
v1.2.85 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ARCCache

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

func NewARC

func NewARC[K comparable, V any](size int) (*ARCCache[K, V], error)

func (*ARCCache[K, V]) Add

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

func (*ARCCache[K, V]) Contains

func (c *ARCCache[K, V]) Contains(key K) bool

func (*ARCCache[K, V]) Get

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

func (*ARCCache[K, V]) Keys

func (c *ARCCache[K, V]) Keys() []K

func (*ARCCache[K, V]) Len

func (c *ARCCache[K, V]) Len() int

func (*ARCCache[K, V]) Peek

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

func (*ARCCache[K, V]) Purge

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

func (*ARCCache[K, V]) Remove

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

func (*ARCCache[K, V]) Values

func (c *ARCCache[K, V]) Values() []V

type Entry

type Entry[K comparable, V any] struct {
	Key          K
	Value        V
	ExpiresAt    time.Time
	ExpireBucket uint8
	// contains filtered or unexported fields
}

func (*Entry[K, V]) PrevEntry

func (e *Entry[K, V]) PrevEntry() *Entry[K, V]

type EvictCallback

type EvictCallback[K comparable, V any] func(key K, value V)

type LRU

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

func New

func New[K comparable, V any](size int, onEvict EvictCallback[K, V]) *LRU[K, V]

func NewWithExpire

func NewWithExpire[K comparable, V any](size int, ttl time.Duration, onEvict EvictCallback[K, V]) *LRU[K, V]

func (*LRU[K, V]) Add

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

func (*LRU[K, V]) Contains

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

func (*LRU[K, V]) Get

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

func (*LRU[K, V]) GetOldest

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

func (*LRU[K, V]) Keys

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

func (*LRU[K, V]) Len

func (c *LRU[K, V]) Len() int

func (*LRU[K, V]) Peek

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

func (*LRU[K, V]) Purge

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

func (*LRU[K, V]) Remove

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

func (*LRU[K, V]) RemoveOldest

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

func (*LRU[K, V]) Resize

func (c *LRU[K, V]) Resize(size int) (evicted int)

func (*LRU[K, V]) Values

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

type List

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

func NewList

func NewList[K comparable, V any]() *List[K, V]

func (*List[K, V]) Back

func (l *List[K, V]) Back() *Entry[K, V]

func (*List[K, V]) Init

func (l *List[K, V]) Init() *List[K, V]

func (*List[K, V]) Length

func (l *List[K, V]) Length() int

func (*List[K, V]) MoveToFront

func (l *List[K, V]) MoveToFront(e *Entry[K, V])

func (*List[K, V]) PushFront

func (l *List[K, V]) PushFront(k K, v V) *Entry[K, V]

func (*List[K, V]) PushFrontExpirable

func (l *List[K, V]) PushFrontExpirable(k K, v V, expiresAt time.Time) *Entry[K, V]

func (*List[K, V]) Remove

func (l *List[K, V]) Remove(e *Entry[K, V]) V

Jump to

Keyboard shortcuts

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