From 45f5eaffa73d3d6489244d52f38b8e2adb29e481 Mon Sep 17 00:00:00 2001 From: yxh Date: Thu, 2 Feb 2023 11:51:52 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E6=89=8B=E5=8A=A8=E6=B8=85=E7=A9=BA?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/v1/system/cache.go | 22 +++++++++ internal/app/system/controller/cache.go | 62 +++++++++++++++++++++++++ internal/app/system/router/router.go | 1 + 3 files changed, 85 insertions(+) create mode 100644 api/v1/system/cache.go create mode 100644 internal/app/system/controller/cache.go diff --git a/api/v1/system/cache.go b/api/v1/system/cache.go new file mode 100644 index 0000000..6a4dcd4 --- /dev/null +++ b/api/v1/system/cache.go @@ -0,0 +1,22 @@ +/* +* @desc:缓存处理 +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @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 +} \ No newline at end of file diff --git a/internal/app/system/controller/cache.go b/internal/app/system/controller/cache.go new file mode 100644 index 0000000..4203d28 --- /dev/null +++ b/internal/app/system/controller/cache.go @@ -0,0 +1,62 @@ +/* +* @desc:缓存处理 +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @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 +} \ No newline at end of file diff --git a/internal/app/system/router/router.go b/internal/app/system/router/router.go index 023503e..e5da03e 100644 --- a/internal/app/system/router/router.go +++ b/internal/app/system/router/router.go @@ -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, //编辑器