com_handler_sys_config.go 591 B

123456789101112131415161718192021222324
  1. package services
  2. import (
  3. "app/commons/core/redisclient"
  4. "app/commons/model/entity"
  5. "fmt"
  6. "time"
  7. )
  8. // 获取资产配置
  9. func (s *CommonService) AssetConfigFromCache() (*entity.AssetConfig, error) {
  10. row := entity.NewAssetConfig()
  11. cacheKey := fmt.Sprintf("asset:confing")
  12. cacheTime := time.Second * 30
  13. err := redisclient.GetJsonDataFromCacheOrDB(cacheKey, cacheTime, &row, func() (interface{}, error) {
  14. results, err1 := GetLast[entity.AssetConfig](s.DB())
  15. if err1 != nil {
  16. return results, fmt.Errorf("AssetConfig get error")
  17. }
  18. return results, nil
  19. })
  20. return row, err
  21. }