cache

package
v0.0.0-...-dae3534 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAliveTime = 3 * time.Hour
)

Variables

This section is empty.

Functions

func DropTable

func DropTable(name string)

func ListTable

func ListTable(filters ...TableFilter) ([]string, errs.InnerError)

Types

type CheckFunc

type CheckFunc func(key interface{}) bool

type Item

type Item struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewCacheItem

func NewCacheItem(key, data interface{}, aliveTime time.Duration) *Item

func (*Item) AccessedOn

func (item *Item) AccessedOn() time.Time

func (*Item) CreatedOn

func (item *Item) CreatedOn() time.Time

func (*Item) Data

func (item *Item) Data() interface{}

func (*Item) KeepAlive

func (item *Item) KeepAlive()

func (*Item) Key

func (item *Item) Key() interface{}

type ObjectEventHandlerFuncs

type ObjectEventHandlerFuncs struct {
	AddFn    func(key, item interface{})
	UpdateFn func(key, item, newItem interface{})
	RemoveFn func(key, item interface{})
}

ObjectEventHandlerFuncs 注册回调函数

type Table

type Table struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func Cache

func Cache(table string, liveTime time.Duration) *Table

Cache create table and save to cache, if table existed, get it and return

func GetTable

func GetTable(table string) (*Table, errs.InnerError)

GetTable search table from cache, and return TableNotFoundErr when table not exist

func (*Table) Add

func (t *Table) Add(key interface{}, value interface{}) (bool, errs.InnerError)

Add 添加CacheItem到table中

func (*Table) Count

func (t *Table) Count() int

Count 返回table中的CacheItem数量

func (*Table) Delete

func (t *Table) Delete(key interface{}) bool

Delete 删除table中的CacheItem,若CacheItem不存在则直接return false

func (*Table) Exists

func (t *Table) Exists(key interface{}) bool

Exists 判断key是否存在于map中

func (*Table) Get

func (t *Table) Get(key interface{}) (interface{}, errs.InnerError)

Get 获取获取指定key的缓存数据

func (*Table) GetAndDelete

func (t *Table) GetAndDelete(key interface{}) (interface{}, errs.InnerError)

GetAndDelete 取出key对应的value的同时,从缓存中删除

func (*Table) List

func (t *Table) List() []interface{}

List 获取缓存中所有的数据

func (*Table) ListCacheInfo

func (t *Table) ListCacheInfo() []*proto.CacheInfo

ListCacheInfo 获取缓存中所有的数据

func (*Table) RangeByKey

func (t *Table) RangeByKey(checkRange CheckFunc) []interface{}

RangeByKey 根据key循环遍历数据

func (*Table) RegisterCallback

func (t *Table) RegisterCallback(obj ObjectEventHandlerFuncs)

RegisterCallback 注册回调函数,进行增删改查操作时回调对应函数

func (*Table) Update

func (t *Table) Update(key interface{}, value interface{}, checkFunc ...UpdateCheckFunc) errs.InnerError

Update 更新table中的CacheItem

func (*Table) UpdateForce

func (t *Table) UpdateForce(key interface{}, value interface{}) bool

UpdateForce 强制更新table中的CacheItem,无论是否存在

type TableFilter

type TableFilter func(item *Table) bool

func NewTableNameFilter

func NewTableNameFilter(name string) TableFilter

type UpdateCheckFunc

type UpdateCheckFunc func(value interface{}) bool

Jump to

Keyboard shortcuts

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