algorithm

package
v0.0.0-...-6126220 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2022 License: Apache-2.0 Imports: 3 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
}

缓存的数据结构体

func New

func New(maxBytes int64, threshold float64, onEivcted func(key string, value Value)) *Cache

Cache 的实例化方法

func (*Cache) Get

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

cache 通过键获得对应的值的方法

func (*Cache) Len

func (c *Cache) Len() int

func (*Cache) Remove

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

主动的移除缓存键值的方法

func (*Cache) RemoveOldest

func (c *Cache) RemoveOldest()

lru的最近最久未使用的淘汰方法

func (*Cache) Set

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

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