cache

package
v0.0.0-...-56e1c70 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package cache holds cache related files

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TwoLayersLRU

type TwoLayersLRU[K1 comparable, K2 comparable, V any] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

TwoLayersLRU defines a two layers LRU cache.

func NewTwoLayersLRU

func NewTwoLayersLRU[K1 comparable, K2 comparable, V any](size int) (*TwoLayersLRU[K1, K2, V], error)

NewTwoLayersLRU returns a new cache.

func (*TwoLayersLRU[K1, K2, V]) Add

func (tll *TwoLayersLRU[K1, K2, V]) Add(k1 K1, k2 K2, v V) bool

Add adds a value to the cache. Returns true if an eviction occurred.

func (*TwoLayersLRU[K1, K2, V]) Get

func (tll *TwoLayersLRU[K1, K2, V]) Get(k1 K1, k2 K2) (v V, ok bool)

Get looks up key values from the cache.

func (*TwoLayersLRU[K1, K2, V]) Len

func (tll *TwoLayersLRU[K1, K2, V]) Len() int

Len returns the number of entries

func (*TwoLayersLRU[K1, K2, V]) RemoveKey1

func (tll *TwoLayersLRU[K1, K2, V]) RemoveKey1(k1 K1) bool

RemoveKey1 the whole layer 2 for the given key1.

func (*TwoLayersLRU[K1, K2, V]) RemoveKey2

func (tll *TwoLayersLRU[K1, K2, V]) RemoveKey2(k1 K1, k2 K2) bool

RemoveKey2 remove the entry in the second layer

func (*TwoLayersLRU[K1, K2, V]) RemoveOldest

func (tll *TwoLayersLRU[K1, K2, V]) RemoveOldest() (K1, K2, V, bool)

RemoveOldest removes the oldest element

func (*TwoLayersLRU[K1, K2, V]) Walk

func (tll *TwoLayersLRU[K1, K2, V]) Walk(cb func(k1 K1, k2 K2, v V))

Walk through all the keys

Jump to

Keyboard shortcuts

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