diff --git a/common/cool/cool.go b/common/cool/cool.go index 8421acb1..b2dc87d5 100644 --- a/common/cool/cool.go +++ b/common/cool/cool.go @@ -54,6 +54,7 @@ func init() { } CacheManager.SetAdapter(gcache.NewAdapterRedis(redis)) IsRedisMode = true + g.DB().GetCache().SetAdapter(gcache.NewAdapterRedis(redis)) //设置数据库 } //Logerebug(ctx, "当前运行模式", RunMode) Loger.Debug(ctx, "当前实例ID:", ProcessFlag) diff --git a/common/cool/service.go b/common/cool/service.go index 0ef3e466..abdf60d9 100644 --- a/common/cool/service.go +++ b/common/cool/service.go @@ -7,7 +7,6 @@ import ( "github.com/gogf/gf/v2/database/gdb" "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/frame/g" - "github.com/gogf/gf/v2/os/gcache" "github.com/gogf/gf/v2/util/gconv" ) @@ -31,7 +30,7 @@ type Service struct { InfoIgnoreProperty string // Info时忽略的字段,多个字段用逗号隔开 UniqueKey g.MapStrStr // 唯一键 key:字段名 value:错误信息 NotNullKey g.MapStrStr // 非空键 key:字段名 value:错误信息 - Cache *gcache.Cache + //Cache *gcache.Cache } // List/Add接口条件配置 @@ -415,10 +414,13 @@ func (s *Service) ModifyBefore(ctx context.Context, method string, param g.MapSt // ModifyAfter 新增|删除|修改后的操作 func (s *Service) ModifyAfter(ctx context.Context, method string, param g.MapStrAny) (err error) { - if s.Cache != nil { - s.Cache.Clear(context.Background()) + // if s.Cache != nil { + // s.Cache.Clear(context.Background()) + + // } + + g.DB().GetCore().ClearCache(context.TODO(), s.Model.TableName()) - } return } diff --git a/modules/blazing/service/effect.go b/modules/blazing/service/effect.go index c453b6d1..3f1914aa 100644 --- a/modules/blazing/service/effect.go +++ b/modules/blazing/service/effect.go @@ -3,9 +3,8 @@ package service import ( "blazing/cool" "blazing/modules/blazing/model" - "context" - "github.com/gogf/gf/v2/os/gcache" + "github.com/gogf/gf/v2/database/gdb" ) type EffectService struct { @@ -13,15 +12,13 @@ type EffectService struct { } func (s *EffectService) Args(id uint32) (int, []int) { - ret, _ := s.Cache.GetOrSetFuncLock(context.Background(), id, func(context.Context) (interface{}, error) { + m := cool.DBM(s.Model).Where("se_idx", id).Cache(gdb.CacheOption{ + // Duration: time.Hour, - m := cool.DBM(s.Model).Where("se_idx", id) - var tt model.PlayerPetSpecialEffect - m.Scan(&tt) - - return tt, nil - }, 0) - tt := ret.Interface().(model.PlayerPetSpecialEffect) + Force: false, + }) + var tt model.PlayerPetSpecialEffect + m.Scan(&tt) return int(tt.Eid), tt.Args @@ -29,7 +26,7 @@ func (s *EffectService) Args(id uint32) (int, []int) { func NewEffectService() *EffectService { return &EffectService{ &cool.Service{ - Cache: gcache.New(), + Model: model.NewPlayerPetSpecialEffect(), }, } diff --git a/modules/blazing/service/pet_fusion_material_service.go b/modules/blazing/service/pet_fusion_material_service.go index 91498115..9acb400a 100644 --- a/modules/blazing/service/pet_fusion_material_service.go +++ b/modules/blazing/service/pet_fusion_material_service.go @@ -4,11 +4,10 @@ import ( "blazing/cool" "blazing/modules/blazing/model" "blazing/modules/dict/service" - "context" "strings" + "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" "github.com/gogf/gf/v2/util/grand" ) @@ -25,7 +24,7 @@ func NewPetFusionMaterialService() *PetFusionMaterialService { return &PetFusionMaterialService{ &cool.Service{ Model: model.NewPetFusionMaterial(), // 绑定PetFusionMaterial模型(默认参数占位) - Cache: gcache.New(), + //Cache: gcache.New(), // PageQueryOp: &cool.QueryOp{KeyWordField: []string{"material1", "material2", "material3", "material4"}}, }, } @@ -46,26 +45,23 @@ func (s *PetFusionMaterialService) Data(Material1 [4]uint32) uint32 { } } - ret, _ := s.Cache.GetOrSetFuncLock(context.Background(), cacheKey, func(context.Context) (interface{}, error) { + m := cool.DBM(s.Model) - m := cool.DBM(s.Model) + var effect *model.PetFusionMaterial //一个特性应该是唯一的,但是我们要获取默认随机特性 + condition := g.Map{ + "material1": fusions[Material1[0]].ID, + "material2": fusions[Material1[1]].ID, + "material3": fusions[Material1[2]].ID, + "material4": fusions[Material1[3]].ID, + "is_enable": 1, + } + m.Where(condition).Cache(gdb.CacheOption{ + // Duration: time.Hour, - var effect *model.PetFusionMaterial //一个特性应该是唯一的,但是我们要获取默认随机特性 - condition := g.Map{ - "material1": fusions[Material1[0]].ID, - "material2": fusions[Material1[1]].ID, - "material3": fusions[Material1[2]].ID, - "material4": fusions[Material1[3]].ID, - "is_enable": 1, - } - m.Where(condition).Scan(&effect) - //这时候有可能效果是空的,那么这时候就再次查询默认的特性,保证每次必会生成一个数据库有的特性 - //也许这个时候的特性配方就是随机从数据库中查找一个特性 - - return effect, nil - }, 0) - - effect := ret.Interface().(*model.PetFusionMaterial) + Force: false, + }).Scan(&effect) + //这时候有可能效果是空的,那么这时候就再次查询默认的特性,保证每次必会生成一个数据库有的特性 + //也许这个时候的特性配方就是随机从数据库中查找一个特性 if effect == nil { effect2s := service.DictInfoServiceS.GetData("effect") diff --git a/modules/blazing/service/pet_fusion_service.go b/modules/blazing/service/pet_fusion_service.go index fe78dc40..2df1416c 100644 --- a/modules/blazing/service/pet_fusion_service.go +++ b/modules/blazing/service/pet_fusion_service.go @@ -3,13 +3,10 @@ package service import ( "blazing/cool" "blazing/modules/blazing/model" - "context" - "fmt" - "strings" "github.com/alpacahq/alpacadecimal" + "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/grand" ) @@ -24,8 +21,8 @@ var PetFusionServiceS = NewPetFusionService() func NewPetFusionService() *PetFusionService { return &PetFusionService{ &cool.Service{ - Model: model.NewPetFusion(), // 绑定PetFusion模型 - Cache: gcache.New(), + Model: model.NewPetFusion(), // 绑定PetFusion模型 + //Cache: gcache.New(), PageQueryOp: &cool.QueryOp{FieldEQ: []string{"is_enable", "main_pet_id", "sub_pet_id", "result_pet_id"}}, }, } @@ -59,38 +56,37 @@ func (s *PetFusionService) Data(p1, p2, rand uint32) uint32 { } func (s *PetFusionService) getData(p1, p2 uint32) []model.PetFusion { - cacheKey := strings.Join([]string{fmt.Sprintf("%d", p1), fmt.Sprintf("%d", p2)}, ":") - //println(cacheKey, "获取融合id") - ret, _ := s.Cache.GetOrSetFuncLock(context.Background(), cacheKey, func(context.Context) (interface{}, error) { - m := cool.DBM(s.Model) + //cacheKey := strings.Join([]string{fmt.Sprintf("%d", p1), fmt.Sprintf("%d", p2)}, ":") + m := cool.DBM(s.Model) - var pet []model.PetFusion //一个特性应该是唯一的,但是我们要获取默认随机特性 - condition := g.Map{ - "main_pet_id": p1, - "sub_pet_id": p2, - "is_enable": 1, - // "hits between ? and ?" : g.Slice{1, 10}, - // "exp > 0" : nil, - // "category" : g.Slice{100, 200}, - } - m.Where(condition).Scan(&pet) - return pet, nil + var pet []model.PetFusion //一个特性应该是唯一的,但是我们要获取默认随机特性 + condition := g.Map{ + "main_pet_id": p1, + "sub_pet_id": p2, + "is_enable": 1, + // "hits between ? and ?" : g.Slice{1, 10}, + // "exp > 0" : nil, + // "category" : g.Slice{100, 200}, + } + m.Where(condition).Cache(gdb.CacheOption{ + // Duration: time.Hour, - }, 0) - return ret.Interface().([]model.PetFusion) + Force: false, + }).Scan(&pet) + return pet } func (s *PetFusionService) def() []model.PetFusion { - //println(cacheKey, "获取融合id") - ret, _ := s.Cache.GetOrSetFuncLock(context.Background(), "-1", func(context.Context) (interface{}, error) { + var pets []model.PetFusion + m := cool.DBM(s.Model) + m.Where("is_enable", 1).Where("is_default", 1).Cache(gdb.CacheOption{ + // Duration: time.Hour, - var pets []model.PetFusion - m := cool.DBM(s.Model) - m.Where("is_enable", 1).Where("is_default", 1).Scan(&pets) + Force: false, + }).Scan(&pets) - return pets, nil - }, 0) - return ret.Interface().([]model.PetFusion) + return pets + // return ret.Interface().([]model.PetFusion) } diff --git a/modules/blazing/service/talkconfig.go b/modules/blazing/service/talkconfig.go index 80e69f62..7a6a8cd5 100644 --- a/modules/blazing/service/talkconfig.go +++ b/modules/blazing/service/talkconfig.go @@ -3,9 +3,8 @@ package service import ( "blazing/cool" "blazing/modules/blazing/model" - "context" - "github.com/gogf/gf/v2/os/gcache" + "github.com/gogf/gf/v2/database/gdb" ) type TalkConfigService struct { @@ -17,19 +16,20 @@ var TalkConfigServiceS = NewTalkConfigService() func NewTalkConfigService() *TalkConfigService { return &TalkConfigService{ - Service: &cool.Service{Model: model.NewMineralCollectionConfig(), - Cache: gcache.New()}, + Service: &cool.Service{Model: model.NewMineralCollectionConfig()}, + // Cache: gcache.New()}, } } func (s *TalkConfigService) GetCache(flag int) []model.MineralCollectionConfig { - ret, _ := s.Cache.GetOrSetFuncLock(context.Background(), flag, func(context.Context) (interface{}, error) { - var config []model.MineralCollectionConfig - cool.DBM(s.Model).Where("type", flag).Scan(&config) - return config, nil - }, 0) - return ret.Interface().([]model.MineralCollectionConfig) + var config []model.MineralCollectionConfig + cool.DBM(s.Model).Where("type", flag).Cache(gdb.CacheOption{ + // Duration: time.Hour, + + Force: false, + }).Scan(&config) + return config }