mirror of
https://github.com/astaxie/beego.git
synced 2025-07-10 02:40:17 +00:00
add comments in cache package files.
This commit is contained in:
22
cache/cache.go
vendored
22
cache/cache.go
vendored
@ -4,14 +4,32 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Cache interface contains all behaviors for cache adapter.
|
||||
// usage:
|
||||
// cache.Register("file",cache.NewFileCache()) // this operation is run in init method of file.go.
|
||||
// c := cache.NewCache("file","{....}")
|
||||
// c.Put("key",value,3600)
|
||||
// v := c.Get("key")
|
||||
//
|
||||
// c.Incr("counter") // now is 1
|
||||
// c.Incr("counter") // now is 2
|
||||
// count := c.Get("counter").(int)
|
||||
type Cache interface {
|
||||
// get cached value by key.
|
||||
Get(key 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 cached value is existed or not.
|
||||
IsExist(key string) bool
|
||||
// clear all cache.
|
||||
ClearAll() error
|
||||
// start gc routine via config string setting.
|
||||
StartAndGC(config string) error
|
||||
}
|
||||
|
||||
@ -30,7 +48,9 @@ func Register(name string, adapter Cache) {
|
||||
adapters[name] = adapter
|
||||
}
|
||||
|
||||
// config need to be correct JSON as string: {"interval":360}
|
||||
// Create a new cache driver by adapter and config string.
|
||||
// config need to be correct JSON as string: {"interval":360}.
|
||||
// it will start gc automatically.
|
||||
func NewCache(adapterName, config string) (Cache, error) {
|
||||
adapter, ok := adapters[adapterName]
|
||||
if !ok {
|
||||
|
Reference in New Issue
Block a user