Documentation ¶
Index ¶
- Variables
- func Register(name string, adapter Cache)
- type Cache
- type DBCache
- func (dc *DBCache) ClearAll() error
- func (dc *DBCache) Decr(key string) error
- func (dc *DBCache) Delete(name string) error
- func (dc *DBCache) Get(name string) interface{}
- func (dc *DBCache) GetMulti(keys []string) []interface{}
- func (dc *DBCache) Incr(key string) error
- func (dc *DBCache) Init(val interface{}) error
- func (dc *DBCache) IsExist(name string) bool
- func (dc *DBCache) Put(name string, value interface{}, expired int64) error
- func (dc *DBCache) StartAndGC(config string) error
- type DBItem
- type MemoryCache
- func (bc *MemoryCache) ClearAll() error
- func (bc *MemoryCache) Decr(key string) error
- func (bc *MemoryCache) Delete(name string) error
- func (bc *MemoryCache) Get(name string) interface{}
- func (bc *MemoryCache) GetMulti(names []string) []interface{}
- func (bc *MemoryCache) Incr(key string) error
- func (bc *MemoryCache) Init(val interface{}) error
- func (bc *MemoryCache) IsExist(name string) bool
- func (bc *MemoryCache) Put(name string, value interface{}, expired int64) error
- func (bc *MemoryCache) StartAndGC(config string) error
- type MemoryItem
Constants ¶
This section is empty.
Variables ¶
View Source
var (
DBInterval int = 30
)
View Source
var ( // clock time of recycling the expired cache items in memory. DefaultEvery int = 60 // 1 minute )
Functions ¶
Types ¶
type Cache ¶
type Cache interface { //get cached value by key. Get(key string) interface{} //GetMulti is a batch version of Get GetMulti(keys []string) []interface{} //set cached value with key and expire time. Put(key string, val interface{}, timeout int64) error //delete cached value by key Delete(key string) error //increase cached int value by key, as a counter. Incr(key string) error //decrease cached int value by key, as a counter. Decr(key string) error //check if cached value exists or not IsExist(key string) bool //clear all cache ClearAll() error //star gc routine based on config string settings. StartAndGC(config string) error //others init Init(val interface{}) error }
c.Incr("counter") //now is 1 c.Incr("counter") // now is 2 count :=c.Get("counter").(int)
var GLCache Cache
type DBCache ¶
type DBCache struct { Every int //run an expiratin check Every clock time DB gorm.DB // contains filtered or unexported fields }
func NewDBCache ¶
func NewDBCache() *DBCache
func (*DBCache) StartAndGC ¶
type DBItem ¶
type DBItem struct { Id int64 `gorm:"column:id;primary_key" json:"id"` UserId int64 `gorm:"column:user_id" json:"user_id"` Tel string `gorm:"column:tel" json:"tel"` AccessToken string `gorm:"column:access_token" json:"access_token"` LastAccess time.Time `gorm:"column:last_access" json:"last_access"` Expired int64 `gorm:"column:expired" json:"expired"` LastAccessIp string `gorm:"column:last_access_ip" json:"last_access_ip"` AppId string `gorm:"column:appid" json:"appid"` ChannelId string `gorm:column:"channel_id" json:"channel_id"` }
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 (*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) Get ¶
func (bc *MemoryCache) Get(name string) interface{}
Get cache from memory. if non-existed or expired, return nil.
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) Init ¶
func (bc *MemoryCache) Init(val interface{}) error
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) error
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(config string) error
start memory cache. it will check expiration in every clock time.
type MemoryItem ¶
Memory cache item.
Click to show internal directories.
Click to hide internal directories.