lru

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ShardLRU

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

ShardLRU 是一个分片式的 LRU 缓存

func NewShardLRU

func NewShardLRU[K comparable, V any](options ...ShardLRUOption[K, V]) *ShardLRU[K, V]

NewShardLRU 创建一个新的分片式 LRU 缓存 shardCount: 分片数量,默认为16,会向上取整为2的幂 capacity: 总容量,会平均分配给所有分片

func (*ShardLRU[K, V]) Clear

func (lru *ShardLRU[K, V]) Clear()

Clear 清空缓存

func (*ShardLRU[K, V]) Contains

func (lru *ShardLRU[K, V]) Contains(key K) bool

Contains 检查键是否存在

func (*ShardLRU[K, V]) Delete

func (lru *ShardLRU[K, V]) Delete(key K) bool

func (*ShardLRU[K, V]) Get

func (lru *ShardLRU[K, V]) Get(key K) (V, bool)

func (*ShardLRU[K, V]) Len

func (lru *ShardLRU[K, V]) Len() int

Len 返回当前缓存中的项目数

func (*ShardLRU[K, V]) Set

func (lru *ShardLRU[K, V]) Set(key K, value V)

func (*ShardLRU[K, V]) Stats

func (lru *ShardLRU[K, V]) Stats() (hitRate float64, shardLoad []float64)

Stats 返回缓存统计信息,包括命中率和每个分片的负载

type ShardLRUOption

type ShardLRUOption[K comparable, V any] func(*ShardLRU[K, V])

func WithCapacity

func WithCapacity[K comparable, V any](capacity int) ShardLRUOption[K, V]

func WithLRUOnEvict

func WithLRUOnEvict[K comparable, V any](onEvict func(K, V)) ShardLRUOption[K, V]

func WithShardCount

func WithShardCount[K comparable, V any](shardCount int) ShardLRUOption[K, V]

Jump to

Keyboard shortcuts

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