mc.cache.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Code generated by $GOPATH/src/go-common/app/tool/cache/mc. DO NOT EDIT.
  2. /*
  3. Package roomNotice is a generated mc cache package.
  4. It is generated from:
  5. type _mc interface {
  6. // 获取某个月消费
  7. // mc: -key=keyShouldNotice
  8. CacheMonthConsume(c context.Context, UID int64, targetID int64, date string) (*roomNotice.MonthConsume, error)
  9. // 保存获取某个月消费
  10. // mc: -key=keyShouldNotice -expire=d.keyShouldNoticeExpire -encode=json|gzip
  11. AddCacheMonthConsume(c context.Context, UID int64, targetID int64, date string, value *roomNotice.MonthConsume) error
  12. }
  13. */
  14. package notice
  15. import (
  16. "context"
  17. "fmt"
  18. "go-common/app/service/live/xuserex/model/roomNotice"
  19. "go-common/library/cache/memcache"
  20. "go-common/library/log"
  21. "go-common/library/stat/prom"
  22. )
  23. var _ _mc
  24. // CacheMonthConsume 获取某个月消费
  25. func (d *Dao) CacheMonthConsume(c context.Context, id int64, targetID int64, date string) (res *roomNotice.MonthConsume, err error) {
  26. conn := d.mc.Get(c)
  27. defer conn.Close()
  28. key := keyShouldNotice(id, targetID, date)
  29. reply, err := conn.Get(key)
  30. if err != nil {
  31. if err == memcache.ErrNotFound {
  32. err = nil
  33. return
  34. }
  35. prom.BusinessErrCount.Incr("mc:CacheMonthConsume")
  36. log.Errorv(c, log.KV("CacheMonthConsume", fmt.Sprintf("%+v", err)), log.KV("key", key))
  37. return
  38. }
  39. res = &roomNotice.MonthConsume{}
  40. err = conn.Scan(reply, res)
  41. if err != nil {
  42. prom.BusinessErrCount.Incr("mc:CacheMonthConsume")
  43. log.Errorv(c, log.KV("CacheMonthConsume", fmt.Sprintf("%+v", err)), log.KV("key", key))
  44. return
  45. }
  46. return
  47. }
  48. // AddCacheMonthConsume 保存获取某个月消费
  49. func (d *Dao) AddCacheMonthConsume(c context.Context, id int64, targetID int64, date string, value *roomNotice.MonthConsume) (err error) {
  50. conn := d.mc.Get(c)
  51. defer conn.Close()
  52. key := keyShouldNotice(id, targetID, date)
  53. item := &memcache.Item{Key: key, Object: value, Expiration: keyShouldNoticeExpire, Flags: memcache.FlagJSON}
  54. if err = conn.Set(item); err != nil {
  55. prom.BusinessErrCount.Incr("mc:AddCacheMonthConsume")
  56. log.Errorv(c, log.KV("AddCacheMonthConsume", fmt.Sprintf("%+v", err)), log.KV("key", key))
  57. return
  58. }
  59. return
  60. }