lru

package
v0.0.0-...-873dfe5 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2021 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 {
	// contains filtered or unexported fields
}

func New

func New(config *CacheConfig) *Cache

func (*Cache) Add

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

按key 添加缓存

func (*Cache) Get

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

获取缓存

func (*Cache) Len

func (c *Cache) Len() int

Len the number of cache entries

func (*Cache) Remove

func (c *Cache) Remove(key string) bool

按key 删除缓存

func (*Cache) RemoveOldest

func (c *Cache) RemoveOldest()

删除最近最少使用的缓存

type CacheConfig

type CacheConfig struct {
	MaxBytes   int64 // 最大使用内存
	MaxEntries int   // 最大缓存数目

	// 淘汰回调函数
	OnEvicted func(string, Value)
}

a config for cache

type Value

type Value interface {
	Len() int
}

Value use Len to count how many bytes it takes

Jump to

Keyboard shortcuts

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