merge from mindoc-org/mindoc and resolved conflict

This commit is contained in:
shiqstone
2021-04-21 20:40:54 +08:00
64 changed files with 722 additions and 547 deletions

30
cache/cache.go vendored
View File

@@ -2,18 +2,26 @@ package cache
import (
"bytes"
"context"
"encoding/gob"
"errors"
"github.com/astaxie/beego/cache"
"github.com/astaxie/beego/logs"
"time"
"github.com/beego/beego/v2/client/cache"
"github.com/beego/beego/v2/core/logs"
)
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")
@@ -57,30 +65,30 @@ func Put(key string, val interface{}, timeout time.Duration) error {
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
View File

@@ -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
}