cache

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MB             = 1024 * 1024
	DefMaxBytes    = 32 * MB
	DefStringBytes = 16
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache 缓存

func New

func New(onEvicted func(key string, value Value)) *Cache

New 实例化

func NewWithBytes

func NewWithBytes(maxBytes int, onEvicted func(key string, value Value)) *Cache

NewWithBytes 指定最大内存实例化

func (*Cache) Add

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

Add 增加

func (*Cache) Del

func (c *Cache) Del(key string)

Del 删除

func (*Cache) Get

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

Get 获取

func (*Cache) ReMoveOldest

func (c *Cache) ReMoveOldest()

ReMoveOldest 缓存淘汰

func (*Cache) Update

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

Update 更新

type Value

type Value interface {
	// Size 用于计算此值的类型所占用的内存
	//防止有些像[]int{1,2,3}这种类型,需要手动计算大小
	Size() int
}

Value 所存储值的类型

Jump to

Keyboard shortcuts

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