cache

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: GPL-3.0 Imports: 2 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 CtorConfig) *Cache

func (*Cache) Capacity

func (c *Cache) Capacity() int

func (*Cache) Contains

func (c *Cache) Contains(key KeyType) bool

func (*Cache) Get

func (c *Cache) Get(key KeyType) (ValueType, bool)

查询缓存中是否存在 key, 存在则 ok = true,并返回 value 不存在,则尝试调用初始化函数生成 value 并存入缓存中,存入成功,也会返回 true

func (*Cache) Len

func (c *Cache) Len() int

func (*Cache) Purge

func (c *Cache) Purge()

func (*Cache) Query

func (c *Cache) Query(key KeyType) (value ValueType, ok bool)

查询缓存中是否存在 key, 存在则 ok = true,并返回 value 不存在则 ok = false

func (*Cache) Remove

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

func (*Cache) Set

func (c *Cache) Set(key KeyType, value ValueType) (evicted bool)

type CtorConfig

type CtorConfig struct {
	Capacity  int
	AllocFunc ValueAllocationFunc
}

type KeyType

type KeyType = interface{}

type ValueAllocationFunc

type ValueAllocationFunc func(key KeyType) (value ValueType, ok bool)

type ValueType

type ValueType = interface{}

Jump to

Keyboard shortcuts

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