Documentation ¶
Overview ¶
Package cache provide a Cache interface and some implement engine Usage:
import(
"github.com/wlhet/beego/cache"
)
bm, err := cache.NewCache("memory", `{"interval":60}`)
Use it like this:
bm.Put("astaxie", 1, 10 * time.Second) bm.Get("astaxie") bm.IsExist("astaxie") bm.Delete("astaxie") more docs http://beego.me/docs/module/cache.md
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateOldToNewAdapter ¶
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 time.Duration) 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 // start gc routine based on config string settings. StartAndGC(config string) error }
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,err := cache.NewCache("file","{....}") c.Put("key",value, 3600 * time.Second) v := c.Get("key") c.Incr("counter") // now is 1 c.Incr("counter") // now is 2 count := c.Get("counter").(int)
func NewCache ¶
NewCache Create a new cache driver by adapter name and config string. config need to be correct JSON as string: {"interval":360}. it will start gc automatically.
func NewFileCache ¶
func NewFileCache() Cache
NewFileCache Create new file cache with no config. the level and expiry need set in method StartAndGC as config string.
Click to show internal directories.
Click to hide internal directories.