dao.cache.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // Code generated by $GOPATH/src/go-common/app/tool/cache/gen. DO NOT EDIT.
  2. /*
  3. Package mcndao is a generated cache proxy package.
  4. It is generated from:
  5. type _cache interface {
  6. //cache: -nullcache=&mcnmodel.McnSign{ID:-1} -check_null_code=$!=nil&&$.ID==-1
  7. McnSign(c context.Context, mcnmid int64) (up *mcnmodel.McnSign, err error)
  8. //cache: -nullcache=&mcnmodel.McnGetDataSummaryReply{IsNull:true} -check_null_code=$!=nil&&$.IsNull
  9. McnDataSummary(c context.Context, mcnmid int64, generateDate time.Time) (res *mcnmodel.McnGetDataSummaryReply, err error)
  10. //cache: -nullcache=&mcnmodel.UpPermissionCache{IsNull:true} -check_null_code=$!=nil&&$.IsNull
  11. UpPermission(c context.Context, signID int64, mid int64) (data *mcnmodel.UpPermissionCache, err error)
  12. }
  13. */
  14. package mcndao
  15. import (
  16. "context"
  17. "go-common/app/interface/main/mcn/model/mcnmodel"
  18. "go-common/library/stat/prom"
  19. "time"
  20. )
  21. var _ _cache
  22. // McnSign get data from cache if miss will call source method, then add to cache.
  23. func (d *Dao) McnSign(c context.Context, id int64) (res *mcnmodel.McnSign, err error) {
  24. addCache := true
  25. res, err = d.CacheMcnSign(c, id)
  26. if err != nil {
  27. addCache = false
  28. err = nil
  29. }
  30. defer func() {
  31. if res != nil && res.ID == -1 {
  32. res = nil
  33. }
  34. }()
  35. if res != nil {
  36. prom.CacheHit.Incr("McnSign")
  37. return
  38. }
  39. prom.CacheMiss.Incr("McnSign")
  40. res, err = d.RawMcnSign(c, id)
  41. if err != nil {
  42. return
  43. }
  44. miss := res
  45. if miss == nil {
  46. miss = &mcnmodel.McnSign{ID: -1}
  47. }
  48. if !addCache {
  49. return
  50. }
  51. d.cache.Do(c, func(c context.Context) {
  52. d.AddCacheMcnSign(c, id, miss)
  53. })
  54. return
  55. }
  56. // McnDataSummary get data from cache if miss will call source method, then add to cache.
  57. func (d *Dao) McnDataSummary(c context.Context, id int64, generateDate time.Time) (res *mcnmodel.McnGetDataSummaryReply, err error) {
  58. addCache := true
  59. res, err = d.CacheMcnDataSummary(c, id, generateDate)
  60. if err != nil {
  61. addCache = false
  62. err = nil
  63. }
  64. defer func() {
  65. if res != nil && res.IsNull {
  66. res = nil
  67. }
  68. }()
  69. if res != nil {
  70. prom.CacheHit.Incr("McnDataSummary")
  71. return
  72. }
  73. prom.CacheMiss.Incr("McnDataSummary")
  74. res, err = d.RawMcnDataSummary(c, id, generateDate)
  75. if err != nil {
  76. return
  77. }
  78. miss := res
  79. if miss == nil {
  80. miss = &mcnmodel.McnGetDataSummaryReply{IsNull: true}
  81. }
  82. if !addCache {
  83. return
  84. }
  85. d.cache.Do(c, func(c context.Context) {
  86. d.AddCacheMcnDataSummary(c, id, miss, generateDate)
  87. })
  88. return
  89. }
  90. // UpPermission get data from cache if miss will call source method, then add to cache.
  91. func (d *Dao) UpPermission(c context.Context, id int64, mid int64) (res *mcnmodel.UpPermissionCache, err error) {
  92. addCache := true
  93. res, err = d.CacheUpPermission(c, id, mid)
  94. if err != nil {
  95. addCache = false
  96. err = nil
  97. }
  98. defer func() {
  99. if res != nil && res.IsNull {
  100. res = nil
  101. }
  102. }()
  103. if res != nil {
  104. prom.CacheHit.Incr("UpPermission")
  105. return
  106. }
  107. prom.CacheMiss.Incr("UpPermission")
  108. res, err = d.RawUpPermission(c, id, mid)
  109. if err != nil {
  110. return
  111. }
  112. miss := res
  113. if miss == nil {
  114. miss = &mcnmodel.UpPermissionCache{IsNull: true}
  115. }
  116. if !addCache {
  117. return
  118. }
  119. d.cache.Do(c, func(c context.Context) {
  120. d.AddCacheUpPermission(c, id, miss, mid)
  121. })
  122. return
  123. }