lru

package
v0.0.0-...-977b0b9 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	OnEvicted func(key string, value Value)
	// contains filtered or unexported fields
}

LRU cache

func New

func New(maxBytes int64, OnEvicted func(string, Value)) *Cache

构造函数

func (*Cache) Add

func (c *Cache) Add(key string, value Value)

添加或修改缓存键值对

func (*Cache) Get

func (c *Cache) Get(key string) (value Value, ok bool)

从缓存中查询key

func (*Cache) Len

func (c *Cache) Len() int

func (*Cache) RemoveOldest

func (c *Cache) RemoveOldest()

缓存淘汰

type Value

type Value interface {
	Len() int
}

实现了Value接口的值都可被Cache接受

Jump to

Keyboard shortcuts

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