mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-09-18 17:48:00 +08:00
1、完善日志配置
2、文章自动生成摘要 3、修正文档名称问题 4、修复Redis无法读取缓存的BUG
This commit is contained in:
40
cache/cache.go
vendored
40
cache/cache.go
vendored
@@ -3,24 +3,56 @@ package cache
|
||||
import (
|
||||
"github.com/astaxie/beego/cache"
|
||||
"time"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"bytes"
|
||||
"errors"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
var bm cache.Cache
|
||||
|
||||
func Get(key string) interface{} {
|
||||
func Get(key string,e interface{}) error {
|
||||
|
||||
return bm.Get(key)
|
||||
val := bm.Get(key)
|
||||
|
||||
if val == nil {
|
||||
return errors.New("cache does not exist")
|
||||
}
|
||||
if b,ok := val.([]byte); ok {
|
||||
buf := bytes.NewBuffer(b)
|
||||
|
||||
decoder := gob.NewDecoder(buf)
|
||||
|
||||
err := decoder.Decode(e)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("反序列化对象失败 ->", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return errors.New("value is not []byte")
|
||||
}
|
||||
|
||||
func GetMulti(keys []string) []interface{} {
|
||||
|
||||
return bm.GetMulti(keys)
|
||||
}
|
||||
|
||||
func Put(key string, val interface{}, timeout time.Duration) error {
|
||||
|
||||
return bm.Put(key, val, timeout)
|
||||
var buf bytes.Buffer
|
||||
|
||||
encoder := gob.NewEncoder(&buf)
|
||||
|
||||
err := encoder.Encode(val)
|
||||
if err != nil {
|
||||
beego.Error("序列化对象失败 ->",err)
|
||||
return err
|
||||
}
|
||||
|
||||
return bm.Put(key, buf.String(), timeout)
|
||||
}
|
||||
|
||||
func Delete(key string) error {
|
||||
return bm.Delete(key)
|
||||
}
|
||||
|
Reference in New Issue
Block a user