mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-09-19 01:58:00 +08:00
chore!(all): attempt to update beego to v2
BREAKING CHANGE: beego has update to v2, and this version of mindoc IS NOT TESTED AND STABLE!!!
This commit is contained in:
42
cache/cache.go
vendored
42
cache/cache.go
vendored
@@ -1,20 +1,27 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego/cache"
|
||||
"time"
|
||||
"encoding/gob"
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/gob"
|
||||
"errors"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/beego/beego/v2/client/cache"
|
||||
)
|
||||
|
||||
var bm cache.Cache
|
||||
|
||||
var nilctx = context.TODO()
|
||||
|
||||
func Get(key string, e interface{}) error {
|
||||
|
||||
val := bm.Get(key)
|
||||
val, err := bm.Get(nilctx, key)
|
||||
|
||||
if err != nil {
|
||||
return errors.New("get cache error:"+ err.Error())
|
||||
}
|
||||
|
||||
if val == nil {
|
||||
return errors.New("cache does not exist")
|
||||
@@ -27,7 +34,7 @@ func Get(key string, e interface{}) error {
|
||||
err := decoder.Decode(e)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("反序列化对象失败 ->", err)
|
||||
logs.Error("反序列化对象失败 ->", err)
|
||||
}
|
||||
return err
|
||||
} else if s, ok := val.(string); ok && s != "" {
|
||||
@@ -39,14 +46,13 @@ func Get(key string, e interface{}) error {
|
||||
err := decoder.Decode(e)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("反序列化对象失败 ->", err)
|
||||
logs.Error("反序列化对象失败 ->", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return errors.New("value is not []byte or string")
|
||||
}
|
||||
|
||||
|
||||
func Put(key string, val interface{}, timeout time.Duration) error {
|
||||
|
||||
var buf bytes.Buffer
|
||||
@@ -55,34 +61,34 @@ func Put(key string, val interface{}, timeout time.Duration) error {
|
||||
|
||||
err := encoder.Encode(val)
|
||||
if err != nil {
|
||||
beego.Error("序列化对象失败 ->", err)
|
||||
logs.Error("序列化对象失败 ->", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return bm.Put(key, buf.String(), timeout)
|
||||
return bm.Put(nilctx, key, buf.String(), timeout)
|
||||
}
|
||||
|
||||
func Delete(key string) error {
|
||||
return bm.Delete(key)
|
||||
return bm.Delete(nilctx, key)
|
||||
}
|
||||
func Incr(key string) error {
|
||||
return bm.Incr(key)
|
||||
return bm.Incr(nilctx, key)
|
||||
}
|
||||
func Decr(key string) error {
|
||||
return bm.Decr(key)
|
||||
return bm.Decr(nilctx, key)
|
||||
}
|
||||
func IsExist(key string) bool {
|
||||
return bm.IsExist(key)
|
||||
func IsExist(key string) (bool, error) {
|
||||
return bm.IsExist(nilctx, key)
|
||||
}
|
||||
func ClearAll() error {
|
||||
return bm.ClearAll()
|
||||
return bm.ClearAll(nilctx)
|
||||
}
|
||||
|
||||
func StartAndGC(config string) error {
|
||||
return bm.StartAndGC(config)
|
||||
}
|
||||
|
||||
//初始化缓存
|
||||
//Init will initialize cache
|
||||
func Init(c cache.Cache) {
|
||||
bm = c
|
||||
}
|
||||
|
27
cache/cache_null.go
vendored
27
cache/cache_null.go
vendored
@@ -1,36 +1,39 @@
|
||||
package cache
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
type NullCache struct {
|
||||
|
||||
}
|
||||
|
||||
|
||||
func (bm *NullCache) Get(key string) interface{} {
|
||||
return nil
|
||||
func (bm *NullCache) Get(ctx context.Context, key string) (interface{}, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (bm *NullCache)GetMulti(keys []string) []interface{} {
|
||||
return nil
|
||||
func (bm *NullCache)GetMulti(ctx context.Context, keys []string) ([]interface{}, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (bm *NullCache)Put(key string, val interface{}, timeout time.Duration) error {
|
||||
func (bm *NullCache)Put(ctx context.Context,key string, val interface{}, timeout time.Duration) error {
|
||||
return nil
|
||||
}
|
||||
func (bm *NullCache)Delete(key string) error {
|
||||
func (bm *NullCache)Delete(ctx context.Context,key string) error {
|
||||
return nil
|
||||
}
|
||||
func (bm *NullCache)Incr(key string) error {
|
||||
func (bm *NullCache)Incr(ctx context.Context,key string) error {
|
||||
return nil
|
||||
}
|
||||
func (bm *NullCache)Decr(key string) error {
|
||||
func (bm *NullCache)Decr(ctx context.Context,key string) error {
|
||||
return nil
|
||||
}
|
||||
func (bm *NullCache)IsExist(key string) bool {
|
||||
return false
|
||||
func (bm *NullCache)IsExist(ctx context.Context,key string) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
func (bm *NullCache)ClearAll() error{
|
||||
func (bm *NullCache)ClearAll(ctx context.Context) error{
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user