From 78bb2bd148948e8e17f83d821533d039489b2efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <1@72wo.cn> Date: Mon, 15 Dec 2025 06:15:55 +0800 Subject: [PATCH] =?UTF-8?q?```=20refactor(dict):=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E9=80=BB=E8=BE=91=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=8E=B7=E5=8F=96=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将原先基于 gcache 的缓存机制移除,改为使用 gdb 内置的 --- modules/blazing/service/effect.go | 2 +- modules/dict/service/dict_info.go | 48 +++++++++++++++---------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/modules/blazing/service/effect.go b/modules/blazing/service/effect.go index 3f1914aaf..4365b8bbe 100644 --- a/modules/blazing/service/effect.go +++ b/modules/blazing/service/effect.go @@ -13,7 +13,7 @@ type EffectService struct { func (s *EffectService) Args(id uint32) (int, []int) { m := cool.DBM(s.Model).Where("se_idx", id).Cache(gdb.CacheOption{ - // Duration: time.Hour, + //Duration: time.Hour, Force: false, }) diff --git a/modules/dict/service/dict_info.go b/modules/dict/service/dict_info.go index 2c75389a5..aa1216519 100644 --- a/modules/dict/service/dict_info.go +++ b/modules/dict/service/dict_info.go @@ -8,8 +8,8 @@ import ( "blazing/modules/dict/model" + "github.com/gogf/gf/v2/database/gdb" "github.com/gogf/gf/v2/frame/g" - "github.com/gogf/gf/v2/os/gcache" "github.com/gogf/gf/v2/util/gconv" ) @@ -61,37 +61,37 @@ func (s *DictInfoService) GetData(types string) (data map[uint32]model.DictInfo) dictInfoModel = model.NewDictInfo() dictTypeModel = model.NewDictType() ) - ret, _ := cacheDict.GetOrSetFunc(context.Background(), types, func(context.Context) (interface{}, error) { - // 如果typeData为空, 则返回空 - var ty *model.DictType - mType := cool.DBM(dictTypeModel) - mType.Where("key in (?)", types).Scan(&ty) + // 如果typeData为空, 则返回空 + var ty *model.DictType + mType := cool.DBM(dictTypeModel) + mType.Where("key in (?)", types).Cache(gdb.CacheOption{ + // Duration: time.Hour, - // 如果typeData为空, 则返回空 - if ty == nil { - return []model.DictInfo{}, nil - } - m := cool.DBM(dictInfoModel) - var ress []model.DictInfo - m.Where("typeId", ty.ID).Scan(&ress) - fusions := utils.ToMap(ress, func(t model.DictInfo) uint32 { + Force: false, + }).Scan(&ty) - return gconv.Uint32(t.Value) //物品id转id - }) - return fusions, nil - }, 0) + // 如果typeData为空, 则返回空 + if ty == nil { + return nil + } + m := cool.DBM(dictInfoModel) + var ress []model.DictInfo + m.Where("typeId", ty.ID).Cache(gdb.CacheOption{ + // Duration: time.Hour, - return ret.Interface().(map[uint32]model.DictInfo) + Force: false, + }).Scan(&ress) + fusions := utils.ToMap(ress, func(t model.DictInfo) uint32 { + + return gconv.Uint32(t.Value) //物品id转id + }) + return fusions } -var ( - cacheDict = gcache.New() -) - // ModifyAfter 修改后 func (s *DictInfoService) ModifyAfter(ctx context.Context, method string, param map[string]interface{}) (err error) { - cacheDict.Clear(context.Background()) + if method == "Delete" { // 删除后,同时删除子节点 ids, ok := param["ids"]