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, //编辑器