zcache

package
v0.1.42 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2020 License: MIT Imports: 5 Imported by: 6

Documentation

Overview

Package zcache cache operation

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 string) (value interface{}, err error)

func GetInt added in v0.1.29

func GetInt(key string) (value int, err error)

func GetString added in v0.1.29

func GetString(key string) (value string, err error)

func MustGet added in v0.1.37

func MustGet(key string, do func(set func(data interface{},
	lifeSpan time.Duration, interval ...bool)) (
	err error)) (data interface{}, err error)

MustGet get the data of the specified key, set if it does not exist

func Set added in v0.0.20

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

func SetDeleteCallback added in v0.0.20

func SetDeleteCallback(fn func(key string) bool)

func SetLogger added in v0.0.20

func SetLogger(logger *zlog.Logger)

Types

type CacheItemPair

type CacheItemPair struct {
	Key         string
	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 string) (*Item, error)

func GetT added in v0.1.37

func GetT(key string) (*Item, error)

func NewCacheItem added in v0.1.29

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

NewCacheItem NewCacheItem

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(key string) 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 string, data interface{}, lifeSpan time.Duration, intervalLifeSpan ...bool) bool

Add if the cache does not exist then adding does not take effect

func (*Table) Clear

func (table *Table) Clear()

Clear Clear

func (*Table) Count

func (table *Table) Count() int

Count get the number of caches

func (*Table) Delete

func (table *Table) Delete(key string) (*Item, error)

Delete Delete cache

func (*Table) Exists

func (table *Table) Exists(key string) bool

Exists Exists

func (*Table) ForEach

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

ForEach traversing the cache

func (*Table) ForEachRaw added in v0.1.37

func (table *Table) ForEachRaw(trans func(key string, value *Item) bool)

ForEachRaw traversing the cache

func (*Table) Get

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

Get get the data of the specified key

func (*Table) GetInt added in v0.1.29

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

func (*Table) GetString added in v0.1.29

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

func (*Table) GetT added in v0.1.37

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

GetT GetT

func (*Table) MostAccessed

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

MostAccessed MostAccessed

func (*Table) MustGet added in v0.1.37

func (table *Table) MustGet(key string, do func(set func(data interface{},
	lifeSpan time.Duration, interval ...bool)) (
	err error)) (data interface{}, err error)

MustGet get the data of the specified key, set if it does not exist

func (*Table) Set

func (table *Table) Set(key string, 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(key string) bool)

SetDeleteCallback SetDeleteCallback

func (*Table) SetLoadNotCallback

func (table *Table) SetLoadNotCallback(f func(key string, 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 string, 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