dao.cache.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Code generated by $GOPATH/src/go-common/app/tool/cache/gen. DO NOT EDIT.
  2. /*
  3. Package dao is a generated cache proxy package.
  4. It is generated from:
  5. type _cache interface {
  6. // cache: -nullcache=&model.OpenBindInfo{Mid:-1} -check_null_code=$!=nil&&$.Mid==-1
  7. BindInfoByMid(c context.Context, mid int64, appID int64) (*model.OpenBindInfo, error)
  8. // cache: -nullcache=&model.OpenInfo{Mid:-1} -check_null_code=$!=nil&&$.Mid==-1
  9. OpenInfoByOpenID(c context.Context, openID string, appID int64) (*model.OpenInfo, error)
  10. }
  11. */
  12. package dao
  13. import (
  14. "context"
  15. "go-common/app/service/main/vip/model"
  16. "go-common/library/stat/prom"
  17. )
  18. var _ _cache
  19. // BindInfoByMid get data from cache if miss will call source method, then add to cache.
  20. func (d *Dao) BindInfoByMid(c context.Context, id int64, appID int64) (res *model.OpenBindInfo, err error) {
  21. addCache := true
  22. res, err = d.CacheBindInfoByMid(c, id, appID)
  23. if err != nil {
  24. addCache = false
  25. err = nil
  26. }
  27. defer func() {
  28. if res != nil && res.Mid == -1 {
  29. res = nil
  30. }
  31. }()
  32. if res != nil {
  33. prom.CacheHit.Incr("BindInfoByMid")
  34. return
  35. }
  36. prom.CacheMiss.Incr("BindInfoByMid")
  37. res, err = d.RawBindInfoByMid(c, id, appID)
  38. if err != nil {
  39. return
  40. }
  41. miss := res
  42. if miss == nil {
  43. miss = &model.OpenBindInfo{Mid: -1}
  44. }
  45. if !addCache {
  46. return
  47. }
  48. d.cache.Do(c, func(c context.Context) {
  49. d.AddCacheBindInfoByMid(c, id, miss, appID)
  50. })
  51. return
  52. }
  53. // OpenInfoByOpenID get data from cache if miss will call source method, then add to cache.
  54. func (d *Dao) OpenInfoByOpenID(c context.Context, id string, appID int64) (res *model.OpenInfo, err error) {
  55. addCache := true
  56. res, err = d.CacheOpenInfoByOpenID(c, id, appID)
  57. if err != nil {
  58. addCache = false
  59. err = nil
  60. }
  61. defer func() {
  62. if res != nil && res.Mid == -1 {
  63. res = nil
  64. }
  65. }()
  66. if res != nil {
  67. prom.CacheHit.Incr("OpenInfoByOpenID")
  68. return
  69. }
  70. prom.CacheMiss.Incr("OpenInfoByOpenID")
  71. res, err = d.RawOpenInfoByOpenID(c, id, appID)
  72. if err != nil {
  73. return
  74. }
  75. miss := res
  76. if miss == nil {
  77. miss = &model.OpenInfo{Mid: -1}
  78. }
  79. if !addCache {
  80. return
  81. }
  82. d.cache.Do(c, func(c context.Context) {
  83. d.AddCacheOpenInfoByOpenID(c, id, miss, appID)
  84. })
  85. return
  86. }