add 手动清空缓存

This commit is contained in:
yxh 2023-02-02 11:51:52 +08:00
parent 33fb5e4243
commit 45f5eaffa7
3 changed files with 85 additions and 0 deletions

22
api/v1/system/cache.go Normal file
View File

@ -0,0 +1,22 @@
/*
* @desc:缓存处理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2023/2/1 18:12
*/
package system
import (
"github.com/gogf/gf/v2/frame/g"
commonApi "github.com/tiger1103/gfast/v3/api/v1/common"
)
type CacheRemoveReq struct {
g.Meta `path:"/cache/remove" tags:"缓存管理" method:"delete" summary:"清除缓存"`
commonApi.Author
}
type CacheRemoveRes struct {
commonApi.EmptyRes
}

View File

@ -0,0 +1,62 @@
/*
* @desc:缓存处理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2023/2/1 18:14
*/
package controller
import (
"context"
"github.com/gogf/gf/v2/container/gvar"
"github.com/gogf/gf/v2/encoding/gbase64"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
"github.com/tiger1103/gfast/v3/api/v1/system"
commonConsts "github.com/tiger1103/gfast/v3/internal/app/common/consts"
"github.com/tiger1103/gfast/v3/internal/app/common/service"
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
)
var Cache = new(cacheController)
type cacheController struct {
BaseController
}
func(c *cacheController)Remove(ctx context.Context,req *system.CacheRemoveReq)(res *system.CacheRemoveRes,err error){
service.Cache().RemoveByTag(ctx,commonConsts.CacheSysDictTag)
service.Cache().RemoveByTag(ctx,commonConsts.CacheSysConfigTag)
service.Cache().RemoveByTag(ctx,consts.CacheSysAuthTag)
cacheRedis := g.Cfg().MustGet(ctx,"system.cache.model").String()
if cacheRedis == commonConsts.CacheModelRedis {
cursor := 0
cachePrefix:=g.Cfg().MustGet(ctx,"system.cache.prefix").String()
for {
var v *gvar.Var
v, err = g.Redis().Do(ctx,"scan", cursor, "match", cachePrefix+"*", "count", "100")
if err != nil {
return
}
data := gconv.SliceAny(v)
var dataSlice []string
err = gconv.Structs(data[1], &dataSlice)
if err != nil {
return
}
for _, d := range dataSlice {
dk := gbase64.MustDecodeToString(d)
_, err = g.Redis().Do(ctx,"del", dk)
if err != nil {
return
}
}
cursor = gconv.Int(data[0])
if cursor == 0 {
break
}
}
}
return
}

View File

@ -47,6 +47,7 @@ func (router *Router) BindController(ctx context.Context, group *ghttp.RouterGro
controller.ToolsGenTable,
controller.Personal,
controller.UserOnline,
controller.Cache, // 缓存处理
controller.Upload, // 普通文件上传
controller.BigUpload, // 大文件上传
controller.UEditor, //编辑器