zcache

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2020 License: MIT Imports: 5 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyNotFound ErrKeyNotFound
	ErrKeyNotFound = errors.New("key is not in cache")
	// ErrKeyNotFoundAndNotCallback ErrKeyNotFoundAndNotCallback
	ErrKeyNotFoundAndNotCallback = errors.New("key is not in cache and no callback is set")
)

Functions

func Clear added in v0.0.20

func Clear()

func Get added in v0.0.20

func Get(key interface{}) (value interface{}, err error)

func Set added in v0.0.20

func Set(key, data interface{}, lifeSpan uint, interval ...bool)

func SetDeleteCallback added in v0.0.20

func SetDeleteCallback(f func(*Item) bool)

func SetLogger added in v0.0.20

func SetLogger(logger *zlog.Logger)

Types

type CacheItemPair

type CacheItemPair struct {
	Key         interface{}
	AccessCount int64
}

CacheItemPair maps key to access counter

type CacheItemPairList

type CacheItemPairList []CacheItemPair

CacheItemPairList CacheItemPairList

func (CacheItemPairList) Len

func (p CacheItemPairList) Len() int

func (CacheItemPairList) Less

func (p CacheItemPairList) Less(i, j int) bool

func (CacheItemPairList) Swap

func (p CacheItemPairList) Swap(i, j int)

type Item added in v0.0.20

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

Item Item

func Delete added in v0.0.20

func Delete(key interface{}) (*Item, error)

func GetRaw added in v0.0.20

func GetRaw(key interface{}) (*Item, error)

func (*Item) AccessCount added in v0.0.20

func (item *Item) AccessCount() int64

AccessCount AccessCount

func (*Item) AccessedTime added in v0.0.20

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

AccessedTime AccessedTime

func (*Item) CreatedTime added in v0.0.20

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

CreatedTime CreatedTime

func (*Item) Data added in v0.0.20

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

Data data

func (*Item) Key added in v0.0.20

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

Key item key

func (*Item) LifeSpan added in v0.0.20

func (item *Item) LifeSpan() time.Duration

LifeSpan LifeSpan

func (*Item) LifeSpanUint added in v0.0.20

func (item *Item) LifeSpanUint() uint

LifeSpanUint LifeSpanUint

func (*Item) RemainingLife added in v0.0.20

func (item *Item) RemainingLife() time.Duration

RemainingLife RemainingLife

func (*Item) SetDeleteCallback added in v0.0.20

func (item *Item) SetDeleteCallback(fn func(item *Item) bool)

SetDeleteCallback SetDeleteCallback

type Table

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

Table Table

func New

func New(table string) *Table

New new cache

func (*Table) Add added in v0.0.19

func (table *Table) Add(key interface{}, data interface{}, lifeSpan time.Duration, intervalLifeSpan ...bool) bool

Add Add

func (*Table) Clear

func (table *Table) Clear()

Clear Clear

func (*Table) Count

func (table *Table) Count() int

Count Count

func (*Table) Delete

func (table *Table) Delete(key interface{}) (*Item, error)

Delete Delete cache

func (*Table) Exists

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

Exists Exists

func (*Table) ForEach

func (table *Table) ForEach(trans func(key, value interface{}))

ForEach ForEach

func (*Table) Get

func (table *Table) Get(key interface{}, args ...interface{}) (value interface{}, err error)

func (*Table) GetRaw added in v0.0.19

func (table *Table) GetRaw(key interface{}, args ...interface{}) (*Item, error)

GetRaw GetRaw

func (*Table) MostAccessed

func (table *Table) MostAccessed(count int64) []*Item

MostAccessed MostAccessed

func (*Table) Set

func (table *Table) Set(key, data interface{}, lifeSpan uint, interval ...bool) *Item

Set set cache whether to automatically renew

func (*Table) SetAddCallback

func (table *Table) SetAddCallback(f func(*Item))

SetAddCallback SetAddCallback

func (*Table) SetDeleteCallback

func (table *Table) SetDeleteCallback(f func(*Item) bool)

SetDeleteCallback SetDeleteCallback

func (*Table) SetLoadNotCallback

func (table *Table) SetLoadNotCallback(f func(key interface{}, args ...interface{}) *Item)

SetLoadNotCallback SetLoadNotCallback

func (*Table) SetLogger

func (table *Table) SetLogger(logger *zlog.Logger)

SetLogger SetLogger

func (*Table) SetRaw added in v0.0.19

func (table *Table) SetRaw(key, data interface{}, lifeSpan time.Duration, intervalLifeSpan ...bool) *Item

SetRaw set cache

Jump to

Keyboard shortcuts

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