mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-05-05 22:24:38 +08:00
修复使用文件做缓存时无法反序列化的BUG
This commit is contained in:
parent
1cbdd4baca
commit
b732cbbdc8
17
cache/cache.go
vendored
17
cache/cache.go
vendored
@ -4,7 +4,6 @@ import (
|
|||||||
"github.com/astaxie/beego/cache"
|
"github.com/astaxie/beego/cache"
|
||||||
"time"
|
"time"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"fmt"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
@ -27,11 +26,23 @@ func Get(key string,e interface{}) error {
|
|||||||
err := decoder.Decode(e)
|
err := decoder.Decode(e)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("反序列化对象失败 ->", err)
|
beego.Error("反序列化对象失败 ->", err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}else if s,ok := val.(string); ok && s != "" {
|
||||||
|
|
||||||
|
buf := bytes.NewBufferString(s)
|
||||||
|
|
||||||
|
decoder := gob.NewDecoder(buf)
|
||||||
|
|
||||||
|
err := decoder.Decode(e)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
beego.Error("反序列化对象失败 ->", err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return errors.New("value is not []byte")
|
return errors.New("value is not []byte or string")
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMulti(keys []string) []interface{} {
|
func GetMulti(keys []string) []interface{} {
|
||||||
|
@ -104,11 +104,14 @@ func (b *Blog) Find(blogId int) (*Blog,error) {
|
|||||||
func (b *Blog) FindFromCache(blogId int) (blog *Blog,err error) {
|
func (b *Blog) FindFromCache(blogId int) (blog *Blog,err error) {
|
||||||
key := fmt.Sprintf("blog-id-%d",blogId);
|
key := fmt.Sprintf("blog-id-%d",blogId);
|
||||||
var temp Blog
|
var temp Blog
|
||||||
if err := cache.Get(key,&temp); err == nil {
|
err = cache.Get(key,&temp);
|
||||||
|
if err == nil {
|
||||||
b = &temp
|
b = &temp
|
||||||
b.Link()
|
b.Link()
|
||||||
beego.Info("从缓存读取文章成功 ->", key)
|
beego.Debug("从缓存读取文章成功 ->", key)
|
||||||
return b,nil
|
return b,nil
|
||||||
|
}else {
|
||||||
|
beego.Error("读取缓存失败 ->",err)
|
||||||
}
|
}
|
||||||
|
|
||||||
blog,err = b.Find(blogId)
|
blog,err = b.Find(blogId)
|
||||||
|
Loading…
Reference in New Issue
Block a user