package service import ( "blazing/cool" "blazing/modules/blazing/model" "context" "github.com/gogf/gf/v2/os/gcache" ) type TalkConfigService struct { *cool.Service } var TalkConfigServiceS = NewTalkConfigService() func NewTalkConfigService() *TalkConfigService { return &TalkConfigService{ 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) }