1
0
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:
傅小黑
2013-12-22 13:35:02 +08:00
parent fc339fc3e0
commit 8b0929b4bc
6 changed files with 108 additions and 13 deletions

22
cache/cache.go vendored
View File

@ -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 {