zcache

package
v1.7.12 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 8 Imported by: 5

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 Raw 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)

Types

type ActionKind added in v1.5.0

type ActionKind int
const (
	SET ActionKind = iota + 1
	GET
	DELETE
)

func (ActionKind) String added in v1.5.0

func (k ActionKind) String() string

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 FastCache added in v1.5.0

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

FastCache concurrent LRU cache structure

func NewFast added in v1.5.0

func NewFast(opt ...func(o *Options)) *FastCache

NewFast Fast LRU cache

func (*FastCache) Callback added in v1.5.0

func (l *FastCache) Callback(h handler)

Callback set callback function for cache

func (*FastCache) Delete added in v1.5.0

func (l *FastCache) Delete(key string)

Delete item by key from cache

func (*FastCache) ForEach added in v1.5.0

func (l *FastCache) ForEach(walker func(key string, iface interface{}) bool)

ForEach walk through all items in cache

func (*FastCache) Get added in v1.5.0

func (l *FastCache) Get(key string) (interface{}, bool)

Get value of key from cache with result

func (*FastCache) GetBytes added in v1.5.0

func (l *FastCache) GetBytes(key string) ([]byte, bool)

GetBytes value of key from cache with result

func (*FastCache) ProvideGet added in v1.5.0

func (l *FastCache) ProvideGet(key string, provide func() (interface{}, bool), expiration ...time.Duration) (interface{}, bool)

ProvideGet get value of key from cache with result and provide default value

func (*FastCache) Set added in v1.5.0

func (l *FastCache) Set(key string, val interface{}, expiration ...time.Duration)

Set an item into cache

func (*FastCache) SetBytes added in v1.5.0

func (l *FastCache) SetBytes(key string, b []byte)

SetBytes an item into cache

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) IntervalLifeSpan added in v0.1.52

func (item *Item) IntervalLifeSpan() bool

LifeSpan LifeSpan

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 Options added in v1.6.4

type Options struct {
	Callback   func(ActionKind, string, uintptr)
	Expiration time.Duration
	Bucket     uint16
	Cap        uint16
	LRU2Cap    uint16
}

type Table

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

Table Table

func New deprecated

func New(table string, accessCount ...bool) *Table

Deprecated: please use zcache.NewFast 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 Raw 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 Raw of the specified key, set if it does not exist

func (*Table) Set

func (table *Table) Set(key string, data interface{}, lifeSpanSecond 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) SetRaw added in v0.0.19

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

SetRaw set cache

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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