mirror of
https://github.com/mindoc-org/mindoc.git
synced 2026-02-27 17:03:57 +08:00
fix:修复旧版本没有标识文档读写缓存失败的BUG
This commit is contained in:
23
cache/cache.go
vendored
23
cache/cache.go
vendored
@@ -9,16 +9,17 @@ import (
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
|
||||
var bm cache.Cache
|
||||
|
||||
func Get(key string,e interface{}) error {
|
||||
func Get(key string, e interface{}) error {
|
||||
|
||||
val := bm.Get(key)
|
||||
|
||||
if val == nil {
|
||||
return errors.New("cache does not exist")
|
||||
}
|
||||
if b,ok := val.([]byte); ok {
|
||||
if b, ok := val.([]byte); ok {
|
||||
buf := bytes.NewBuffer(b)
|
||||
|
||||
decoder := gob.NewDecoder(buf)
|
||||
@@ -29,7 +30,7 @@ func Get(key string,e interface{}) error {
|
||||
beego.Error("反序列化对象失败 ->", err)
|
||||
}
|
||||
return err
|
||||
}else if s,ok := val.(string); ok && s != "" {
|
||||
} else if s, ok := val.(string); ok && s != "" {
|
||||
|
||||
buf := bytes.NewBufferString(s)
|
||||
|
||||
@@ -38,16 +39,13 @@ func Get(key string,e interface{}) error {
|
||||
err := decoder.Decode(e)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("反序列化对象失败 ->", err)
|
||||
}
|
||||
beego.Error("反序列化对象失败 ->", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return errors.New("value is not []byte or string")
|
||||
}
|
||||
|
||||
func GetMulti(keys []string) []interface{} {
|
||||
return bm.GetMulti(keys)
|
||||
}
|
||||
|
||||
func Put(key string, val interface{}, timeout time.Duration) error {
|
||||
|
||||
@@ -57,7 +55,7 @@ func Put(key string, val interface{}, timeout time.Duration) error {
|
||||
|
||||
err := encoder.Encode(val)
|
||||
if err != nil {
|
||||
beego.Error("序列化对象失败 ->",err)
|
||||
beego.Error("序列化对象失败 ->", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -76,14 +74,15 @@ func Decr(key string) error {
|
||||
func IsExist(key string) bool {
|
||||
return bm.IsExist(key)
|
||||
}
|
||||
func ClearAll() error{
|
||||
func ClearAll() error {
|
||||
return bm.ClearAll()
|
||||
}
|
||||
|
||||
func StartAndGC(config string) error {
|
||||
return bm.StartAndGC(config)
|
||||
}
|
||||
|
||||
//初始化缓存
|
||||
func Init(c cache.Cache) {
|
||||
func Init(c cache.Cache) {
|
||||
bm = c
|
||||
}
|
||||
}
|
||||
|
||||
2
cache/cache_null.go
vendored
2
cache/cache_null.go
vendored
@@ -7,7 +7,7 @@ type NullCache struct {
|
||||
}
|
||||
|
||||
|
||||
func (bm *NullCache)Get(key string) interface{} {
|
||||
func (bm *NullCache) Get(key string) interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user