lru

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2022 License: BSD-3-Clause 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
}

LRU缓存 https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)

func NewCache

func NewCache(size int, onEvicted func(k, v interface{})) *Cache

func (*Cache) Cap

func (c *Cache) Cap() int

func (*Cache) Contains added in v0.1.17

func (c *Cache) Contains(key interface{}) bool

查看key是否存在,不移动链表

func (*Cache) Get

func (c *Cache) Get(key interface{}) (interface{}, bool)

获取key对应的值,并把其移动到链表头部

func (*Cache) GetOldest

func (c *Cache) GetOldest() (key, value interface{}, ok bool)

获取最老的值(链表尾节点)

func (*Cache) Keys

func (c *Cache) Keys() []interface{}

返回所有的key(从旧到新)

func (*Cache) Len

func (c *Cache) Len() int

func (*Cache) Peek

func (c *Cache) Peek(key interface{}) (interface{}, bool)

获取key对应的值,不移动链表

func (*Cache) Purge added in v0.1.17

func (c *Cache) Purge()

清除所有

func (*Cache) Put

func (c *Cache) Put(key interface{}, value interface{}) bool

把key-value加入到cache中,并移动到链表头部

func (*Cache) Remove

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

把key从cache中删除

func (*Cache) RemoveOldest

func (c *Cache) RemoveOldest() (key, value interface{}, ok bool)

删除最老的的key-value,并返回

func (*Cache) Resize added in v0.1.17

func (c *Cache) Resize(size int) int

Resize changes the cache size.

type Entry

type Entry struct {
	Key   interface{}
	Value interface{}
}

Jump to

Keyboard shortcuts

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