Documentation
¶
Index ¶
- type ShardLRU
- func (lru *ShardLRU[K, V]) Clear()
- func (lru *ShardLRU[K, V]) Contains(key K) bool
- func (lru *ShardLRU[K, V]) Delete(key K) bool
- func (lru *ShardLRU[K, V]) Get(key K) (V, bool)
- func (lru *ShardLRU[K, V]) Len() int
- func (lru *ShardLRU[K, V]) Set(key K, value V)
- func (lru *ShardLRU[K, V]) Stats() (hitRate float64, shardLoad []float64)
- type ShardLRUOption
- type SimpleLRU
- func (lru *SimpleLRU[K, V]) Capacity() int
- func (lru *SimpleLRU[K, V]) Clear()
- func (lru *SimpleLRU[K, V]) Contains(key K) bool
- func (lru *SimpleLRU[K, V]) Delete(key K) bool
- func (lru *SimpleLRU[K, V]) Get(key K) (V, bool)
- func (lru *SimpleLRU[K, V]) Len() int
- func (lru *SimpleLRU[K, V]) OnEvict() func(K, V)
- func (lru *SimpleLRU[K, V]) Set(key K, value V)
- func (lru *SimpleLRU[K, V]) SetOnEvict(onEvict func(K, V))
- func (lru *SimpleLRU[K, V]) Size() int
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: 总容量,会平均分配给所有分片
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]
type SimpleLRU ¶ added in v1.0.2
type SimpleLRU[K comparable, V any] struct { // contains filtered or unexported fields }
func NewSimpleLRU ¶ added in v1.0.2
func NewSimpleLRU[K comparable, V any](capacity int, onEvict func(K, V)) *SimpleLRU[K, V]
func (*SimpleLRU[K, V]) Set ¶ added in v1.0.2
func (lru *SimpleLRU[K, V]) Set(key K, value V)
Set 设置键值对,如果键已存在则更新值并移到头部
func (*SimpleLRU[K, V]) SetOnEvict ¶ added in v1.0.2
func (lru *SimpleLRU[K, V]) SetOnEvict(onEvict func(K, V))
Click to show internal directories.
Click to hide internal directories.