cache

package
v0.2.11 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeString = iota + 1
	TypeByteArray
	TypeMap
	TypeMapSlice
)
View Source
const KB = 1 << 10
View Source
const MB = 1 << 20

Variables

View Source
var LRUCache = NewLRUCache(10 * MB)
View Source
var Uninitialized = errors.New("缓存未初始化")

缓存未初始化

Functions

func CheckError

func CheckError(err error)

func Forget added in v0.1.6

func Forget(key string) bool

Forget 删除缓存

func Has added in v0.1.6

func Has(key string) bool

Has 判断缓存是否存在

func Init added in v0.1.6

func Init(adapterName string, opt map[string]interface{})

Init 初始化设置 在框架初始化时调用 adapterName 适配器名称 ext 选项

Types

type ByteArrayCall

type ByteArrayCall func() []byte

type Cache

type Cache interface {
	Remember(key string, value interface{}, ttl time.Duration) DataResult
	Get(key string) (DataResult, error)
	Has(key string) bool
	Forget(key string) bool
}

type DataResult

type DataResult interface {
	GetType() int32
	ToString() (string, error)
	ToByteArray() ([]byte, error)
	ToMap() (Map, error)
	ToMapSlice() (MapSlice, error)
}

func Get added in v0.1.6

func Get(key string) (DataResult, error)

Get 获取缓存

func Remember added in v0.1.6

func Remember(key string, value interface{}, ttl time.Duration) DataResult

Remember 设置缓存

type LRU

type LRU interface {
	Get(key string) (v Value, ok bool)
	Set(key string, value Value)
	Delete(key string) bool
	Clear()
}

func NewLRUCache

func NewLRUCache(capacity uint64) LRU

构造函数

type LRUImpl

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

定义LRU缓存结构体

func (*LRUImpl) Clear

func (lru *LRUImpl) Clear()

清空缓存

func (*LRUImpl) Delete

func (lru *LRUImpl) Delete(key string) bool

删除缓存

func (*LRUImpl) Get

func (lru *LRUImpl) Get(key string) (v Value, ok bool)

获取缓存

func (*LRUImpl) Set

func (lru *LRUImpl) Set(key string, value Value)

设置缓存

type Map added in v0.1.6

type Map map[string]interface{}

type MapCall added in v0.1.6

type MapCall func() Map

type MapSlice added in v0.1.6

type MapSlice []map[string]interface{}

type MapSliceCall added in v0.1.6

type MapSliceCall func() MapSlice

type StringCall

type StringCall func() string

type Value

type Value []byte

定义Value类型为byte数组

Jump to

Keyboard shortcuts

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