From fc968575be720c1db2682648d1a8d702c2562564 Mon Sep 17 00:00:00 2001 From: yxh Date: Thu, 28 Apr 2022 09:42:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?middleware=20=E4=B8=AD=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E6=9D=83=E9=99=90=E6=9C=AA=E5=88=A4=E6=96=AD=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/app/system/service/middleware.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/app/system/service/middleware.go b/internal/app/system/service/middleware.go index 397affc..1bf1987 100644 --- a/internal/app/system/service/middleware.go +++ b/internal/app/system/service/middleware.go @@ -83,7 +83,7 @@ func (s *middlewareImpl) Auth(r *ghttp.Request) { return } //获取地址对应的菜单id - menuList, err := Rule().GetIsMenuList(ctx) + menuList, err := Rule().GetMenuList(ctx) if err != nil { g.Log().Error(ctx, err) libResponse.FailJson(true, r, "请求数据失败") From e554abe8cffa1b7b47205363c4e997be04933eda Mon Sep 17 00:00:00 2001 From: yxh Date: Wed, 18 May 2022 15:02:09 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E5=86=85=E5=AD=98?= =?UTF-8?q?=E7=BC=93=E5=AD=98-=E5=8D=95=E4=BE=8B=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/app/common/service/cache.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/internal/app/common/service/cache.go b/internal/app/common/service/cache.go index 44f43b1..e25eee8 100644 --- a/internal/app/common/service/cache.go +++ b/internal/app/common/service/cache.go @@ -12,6 +12,7 @@ import ( "github.com/gogf/gf/v2/os/gctx" "github.com/tiger1103/gfast-cache/cache" "github.com/tiger1103/gfast/v3/internal/app/common/consts" + "sync" ) type ICache interface { @@ -23,7 +24,11 @@ type cacheImpl struct { prefix string } -var c = cacheImpl{} +var ( + c = cacheImpl{} + cacheContainer *cache.GfCache + lock = &sync.Mutex{} +) func Cache() ICache { var ( @@ -32,11 +37,19 @@ func Cache() ICache { ) prefix := g.Cfg().MustGet(ctx, "system.cache.prefix").String() model := g.Cfg().MustGet(ctx, "system.cache.model").String() - if model == consts.CacheModelRedis { - // redis - ch.GfCache = cache.NewRedis(prefix) - } else { - ch.GfCache = cache.New(prefix) + if cacheContainer == nil { + lock.Lock() + if cacheContainer == nil { + if model == consts.CacheModelRedis { + // redis + cacheContainer = cache.NewRedis(prefix) + } else { + // memory + cacheContainer = cache.New(prefix) + } + } + lock.Unlock() } + ch.GfCache = cacheContainer return &ch }