cache

package
v0.0.0-...-5be9e78 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// clock time of recycling the expired cache items in memory.
	DefaultEvery int = 60 // 1 minute
)

Functions

This section is empty.

Types

type MemoryCache

type MemoryCache struct {
	Every int // run an expiration check Every clock time
	// contains filtered or unexported fields
}

Memory cache adapter. it contains a RW locker for safe map storage.

func NewMemoryCache

func NewMemoryCache(autoGC bool) *MemoryCache

NewMemoryCache returns a new MemoryCache.

func (*MemoryCache) ClearAll

func (bc *MemoryCache) ClearAll() error

delete all cache in memory.

func (*MemoryCache) Decr

func (bc *MemoryCache) Decr(key string) error

Decrease counter in memory.

func (*MemoryCache) Delete

func (bc *MemoryCache) Delete(name string) error

/ Delete cache in memory.

func (*MemoryCache) ExpiredCallback

func (bc *MemoryCache) ExpiredCallback(name string) error

func (*MemoryCache) Get

func (bc *MemoryCache) Get(name string) interface{}

Get cache from memory. if non-existed or expired, return nil.

func (*MemoryCache) GetAll

func (bc *MemoryCache) GetAll() []interface{}

get all cache in memory.

func (*MemoryCache) GetAllEx

func (bc *MemoryCache) GetAllEx() map[string]interface{}

func (*MemoryCache) GetMulti

func (bc *MemoryCache) GetMulti(names []string) []interface{}

GetMulti gets caches from memory. if non-existed or expired, return nil.

func (*MemoryCache) Incr

func (bc *MemoryCache) Incr(key string) error

Increase cache counter in memory. it supports int,int64,int32,uint,uint64,uint32.

func (*MemoryCache) IsExist

func (bc *MemoryCache) IsExist(name string) bool

check cache exist in memory.

func (*MemoryCache) Put

func (bc *MemoryCache) Put(name string, value interface{}, expired int64) *MemoryItem

Put cache to memory. if expired is 0, it will be cleaned by next gc operation ( default gc clock is 1 minute).

func (*MemoryCache) StartAndGC

func (bc *MemoryCache) StartAndGC(interval int) error

start memory cache. it will check expiration in every clock time.

func (*MemoryCache) ThrowError

func (bc *MemoryCache) ThrowError(str string) error

type MemoryItem

type MemoryItem struct {
	Lastaccess time.Time
	// contains filtered or unexported fields
}

Memory cache item.

func (*MemoryItem) RegisterExpiredCallback

func (m *MemoryItem) RegisterExpiredCallback(fn func(m interface{}) error)

Jump to

Keyboard shortcuts

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