dao.cache.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Code generated by $GOPATH/src/go-common/app/tool/cache/gen. DO NOT EDIT.
  2. /*
  3. Package roomNotice is a generated cache proxy package.
  4. It is generated from:
  5. type _cache interface {
  6. // cache: -sync=true -nullcache=&roomNotice.MonthConsume{Amount:-1} -check_null_code=$.Amount==-1
  7. MonthConsume(c context.Context, UID int64, targetID int64, date string) (*roomNotice.MonthConsume, error)
  8. }
  9. */
  10. package notice
  11. import (
  12. "context"
  13. "go-common/app/service/live/xuserex/model/roomNotice"
  14. "go-common/library/log"
  15. "go-common/library/stat/prom"
  16. )
  17. var _ _cache
  18. // MonthConsume get data from cache if miss will call source method, then add to cache.
  19. func (d *Dao) MonthConsume(c context.Context, id int64, targetID int64, date string) (res *roomNotice.MonthConsume, err error) {
  20. addCache := true
  21. res, err = d.CacheMonthConsume(c, id, targetID, date)
  22. if err != nil {
  23. addCache = false
  24. err = nil
  25. }
  26. defer func() {
  27. if nil != res && res.Amount == -1 {
  28. res = nil
  29. }
  30. }()
  31. if res != nil {
  32. prom.CacheHit.Incr("MonthConsume")
  33. return
  34. }
  35. prom.CacheMiss.Incr("MonthConsume")
  36. res, err = d.RawMonthConsume(c, id, targetID, date)
  37. log.Info("MonthConsume_RawMonthConsume uid (%v) targetId (%v) date (%v) res (%+v)", id, targetID, date, res)
  38. if err != nil {
  39. return
  40. }
  41. miss := res
  42. if miss == nil {
  43. miss = &roomNotice.MonthConsume{Amount: -1}
  44. }
  45. if !addCache {
  46. return
  47. }
  48. d.AddCacheMonthConsume(c, id, targetID, date, miss)
  49. return
  50. }