lru

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 27, 2025 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package lru

(C) Copyright Alex Gaetano Padula

Licensed under the Mozilla Public License, v. 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.mozilla.org/en-US/MPL/2.0/

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EvictionCallback added in v0.3.0

type EvictionCallback func(key, value interface{})

type LRU

type LRU struct {
	// contains filtered or unexported fields
}

LRU is a lockless linked list with lazy eviction and anti-thrashing mechanisms

func New

func New(capacity int64, evictRatio float64, accessWeight float64) *LRU

New creates a new lru atomic linked list with lazy eviction

func (*LRU) Clear

func (list *LRU) Clear()

Clear empties the list

func (*LRU) Delete

func (list *LRU) Delete(key interface{}) bool

Delete removes a node by key

func (*LRU) ForEach

func (list *LRU) ForEach(fn func(key, value interface{}, accessCount uint64) bool)

ForEach iterates through the list safely

func (*LRU) ForceEvictionProcessing added in v0.3.2

func (list *LRU) ForceEvictionProcessing()

ForceEvictionProcessing forces the processing of the eviction queue ***************This is mainly for testing purposes to ensure eviction happens immediately

func (*LRU) Get

func (list *LRU) Get(key interface{}) (interface{}, bool)

Get retrieves a value by key with lazy eviction

func (*LRU) Length

func (list *LRU) Length() int64

Length returns the current length of the list

func (*LRU) Put

func (list *LRU) Put(key, value interface{}, onEvict ...EvictionCallback) bool

Put adds or updates a key-value pair with anti-thrashing mechanisms

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node represents a node in the linked list

type ValueWrapper added in v0.3.0

type ValueWrapper struct {
	// contains filtered or unexported fields
}

ValueWrapper is a wrapper for values stored in the LRU list

Jump to

Keyboard shortcuts

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