1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-10 02:30:18 +00:00

Make redis cache timeout not trivial.

- Instead of using HASH for all the caches, use HASH + normal KEYs.
- HASH being used as a collection of all KEYs, this is useful when
  application wants to clear all keys.
This commit is contained in:
reterVision
2014-07-05 22:27:31 +08:00
parent cbffcaa7a8
commit 2933d1fedd
3 changed files with 118 additions and 14 deletions

8
cache/cache.go vendored
View File

@ -35,11 +35,11 @@ type Cache interface {
Incr(key string) error
// decrease cached int value by key, as a counter.
Decr(key string) error
// check cached value is existed or not.
// check if cached value exists or not.
IsExist(key string) bool
// clear all cache.
ClearAll() error
// start gc routine via config string setting.
// start gc routine based on config string settings.
StartAndGC(config string) error
}
@ -58,13 +58,13 @@ func Register(name string, adapter Cache) {
adapters[name] = adapter
}
// Create a new cache driver by adapter and config string.
// 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 NewCache(adapterName, config string) (Cache, error) {
adapter, ok := adapters[adapterName]
if !ok {
return nil, fmt.Errorf("cache: unknown adaptername %q (forgotten import?)", adapterName)
return nil, fmt.Errorf("cache: unknown adapter name %q (forgot to import?)", adapterName)
}
err := adapter.StartAndGC(config)
if err != nil {