feat(common): 为Service结构体添加缓存支持

在common/cool/service.go中引入gcache包,并在Service结构体中增加Cache字段。同时,在ModifyAfter方法中添加了缓存清理逻辑,确保数据变更后缓存能够及时更新。

该变更影响所有使用Service的模块,包括effect、pet_fusion_material_service和pet_fusion_service等,这些模块现在可以通过统一的缓存机制提升性能。
```
This commit is contained in:
2025-12-08 19:31:59 +08:00
parent ec0552b59a
commit 0acf01cd6b
6 changed files with 47 additions and 50 deletions

View File

@@ -7,6 +7,7 @@ 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"
)
@@ -30,6 +31,7 @@ type Service struct {
InfoIgnoreProperty string // Info时忽略的字段,多个字段用逗号隔开
UniqueKey g.MapStrStr // 唯一键 key:字段名 value:错误信息
NotNullKey g.MapStrStr // 非空键 key:字段名 value:错误信息
Cache *gcache.Cache
}
// List/Add接口条件配置
@@ -413,6 +415,10 @@ 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())
}
return
}