eviction

package
v0.1.0-alpha Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FIFO

type FIFO[T comparable] struct {
	// contains filtered or unexported fields
}

FIFO implements the First In, First Out eviction policy.

func (*FIFO[T]) Delete

func (f *FIFO[T]) Delete(key T)

Delete removes a key from the cache.

func (*FIFO[T]) Evict

func (f *FIFO[T]) Evict() (T, bool)

Evict removes the oldest key from the cache.

func (*FIFO[T]) Put

func (f *FIFO[T]) Put(key T) (T, bool)

Put adds a key to the cache. If the cache is full, it evicts the oldest key.

func (*FIFO[T]) Reset

func (f *FIFO[T]) Reset()

Reset clears all keys from the cache.

func (*FIFO[T]) Size

func (f *FIFO[T]) Size() int

Size returns the current number of keys in the cache.

type LFU

type LFU[T comparable] struct {
	// contains filtered or unexported fields
}

LFU implements the Least Frequently Used eviction policy.

func (*LFU[T]) Delete

func (l *LFU[T]) Delete(key T)

Delete removes a key from the cache.

func (*LFU[T]) Evict

func (l *LFU[T]) Evict() (T, bool)

Evict removes the least frequently used key from the cache.

func (*LFU[T]) Put

func (l *LFU[T]) Put(key T) (T, bool)

Put adds a key to the cache. If the cache is full, it evicts the least frequently used key.

func (*LFU[T]) Reset

func (l *LFU[T]) Reset()

Reset clears all keys from the cache.

func (*LFU[T]) Size

func (l *LFU[T]) Size() int

Size returns the current number of keys in the cache.

type Policy

type Policy[T comparable] interface {
	Put(key T) (T, bool) // Adds a key to the cache, returns the evicted key if any.
	Delete(key T)        // Removes a key from the cache.
	Evict() (T, bool)    // Evicts a key from the cache based on the policy.
	Reset()              // Clears all keys from the cache.
	Size() int           // Returns the current number of keys in the cache.
}

Policy defines the interface for cache eviction policies.

func NewFIFO

func NewFIFO[T comparable](capacity int) Policy[T]

NewFIFO creates a new FIFO cache with the given capacity.

func NewLFU

func NewLFU[T comparable](capacity int) Policy[T]

NewLFU creates a new LFU cache with the given capacity.

func NewLRU

func NewLRU[T comparable](capacity int) Policy[T]

NewLRU creates a new lru cache with the given capacity.

Jump to

Keyboard shortcuts

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