lruCache

package
v0.0.0-...-61197bd Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EvictCallback

type EvictCallback func(key interface{}, value interface{})

当有元素被剔除时,执行这个回调

type LRU

type LRU struct {
	// contains filtered or unexported fields
}

func NewLRU

func NewLRU(size int, timeout time.Duration, onEvict EvictCallback) (*LRU, error)

func (*LRU) Add

func (c *LRU) Add(key, value interface{}) (evicted bool)

func (*LRU) Clear

func (c *LRU) Clear()

*

*清楚缓存中所以的元素

func (*LRU) Contains

func (c *LRU) Contains(key interface{}) (ok bool)

Contains 判断缓存中是否包含指定key的元素

func (*LRU) Get

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

Get 获取key 的缓存数据

func (*LRU) Keys

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

*

*Keys返回缓存中所有键的一个切片,顺序从最老的到最新的

func (*LRU) Len

func (c *LRU) Len() int

func (*LRU) Remove

func (c *LRU) Remove(key interface{}) (present bool)

*

  • 移除缓存中指定key的元素

func (*LRU) RemoveOldest

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

* *从缓存中删除最老元素

Jump to

Keyboard shortcuts

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