dao.cache.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Code generated by $GOPATH/src/go-common/app/tool/cache/gen. DO NOT EDIT.
  2. /*
  3. Package anchorReward is a generated cache proxy package.
  4. It is generated from:
  5. type _cache interface {
  6. // cache: -sync=true -nullcache=&model.AnchorRewardConf{ID:-1} -check_null_code=$.ID==-1
  7. RewardConf(c context.Context, id int64) (*model.AnchorRewardConf, error)
  8. }
  9. */
  10. package anchorReward
  11. import (
  12. "context"
  13. model "go-common/app/service/live/xrewardcenter/model/anchorTask"
  14. "go-common/library/stat/prom"
  15. )
  16. var _ _cache
  17. // RewardConf get data from cache if miss will call source method, then add to cache.
  18. func (d *Dao) RewardConf(c context.Context, id int64) (res *model.AnchorRewardConf, err error) {
  19. addCache := true
  20. res, err = d.CacheRewardConf(c, id)
  21. if err != nil {
  22. addCache = false
  23. err = nil
  24. }
  25. defer func() {
  26. if res != nil && res.ID == -1 {
  27. res = nil
  28. }
  29. }()
  30. if res != nil {
  31. prom.CacheHit.Incr("RewardConf")
  32. return
  33. }
  34. prom.CacheMiss.Incr("RewardConf")
  35. res, err = d.RawRewardConf(c, id)
  36. if err != nil {
  37. return
  38. }
  39. miss := res
  40. if miss == nil {
  41. miss = &model.AnchorRewardConf{ID: -1}
  42. }
  43. if !addCache {
  44. return
  45. }
  46. d.AddCacheRewardConf(c, id, miss)
  47. return
  48. }