dao.cache.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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.Notice{Notice:"ff2364a0be3d20e46cc69efb36afe9a5"} -check_null_code=$.Notice=="ff2364a0be3d20e46cc69efb36afe9a5"
  7. Notice(c context.Context, mid int64) (*model.Notice, error)
  8. // cache: -nullcache=&model.AidReason{Aid:-1} -check_null_code=$!=nil&&$.Aid==-1
  9. TopArc(c context.Context, mid int64) (*model.AidReason, error)
  10. // cache: -nullcache=&model.AidReasons{List:[]*model.AidReason{{Aid:-1}}} -check_null_code=len($.List)==1&&$.List[0].Aid==-1
  11. Masterpiece(c context.Context, mid int64) (*model.AidReasons, error)
  12. // cache: -nullcache=&model.ThemeDetails{List:[]*model.ThemeDetail{{ID:-1}}} -check_null_code=len($.List)==1&&$.List[0].ID==-1
  13. Theme(c context.Context, mid int64) (*model.ThemeDetails, error)
  14. // cache: -nullcache=-1 -check_null_code=$==-1
  15. TopDynamic(c context.Context, mid int64) (int64, error)
  16. }
  17. */
  18. package dao
  19. import (
  20. "context"
  21. "go-common/app/interface/main/space/model"
  22. "go-common/library/stat/prom"
  23. )
  24. var _ _cache
  25. // Notice get data from cache if miss will call source method, then add to cache.
  26. func (d *Dao) Notice(c context.Context, id int64) (res *model.Notice, err error) {
  27. addCache := true
  28. res, err = d.CacheNotice(c, id)
  29. if err != nil {
  30. addCache = false
  31. err = nil
  32. }
  33. defer func() {
  34. if res.Notice == "ff2364a0be3d20e46cc69efb36afe9a5" {
  35. res = nil
  36. }
  37. }()
  38. if res != nil {
  39. prom.CacheHit.Incr("Notice")
  40. return
  41. }
  42. prom.CacheMiss.Incr("Notice")
  43. res, err = d.RawNotice(c, id)
  44. if err != nil {
  45. return
  46. }
  47. miss := res
  48. if miss == nil {
  49. miss = &model.Notice{Notice: "ff2364a0be3d20e46cc69efb36afe9a5"}
  50. }
  51. if !addCache {
  52. return
  53. }
  54. d.cache.Do(c, func(c context.Context) {
  55. d.AddCacheNotice(c, id, miss)
  56. })
  57. return
  58. }
  59. // TopArc get data from cache if miss will call source method, then add to cache.
  60. func (d *Dao) TopArc(c context.Context, id int64) (res *model.AidReason, err error) {
  61. addCache := true
  62. res, err = d.CacheTopArc(c, id)
  63. if err != nil {
  64. addCache = false
  65. err = nil
  66. }
  67. defer func() {
  68. if res != nil && res.Aid == -1 {
  69. res = nil
  70. }
  71. }()
  72. if res != nil {
  73. prom.CacheHit.Incr("TopArc")
  74. return
  75. }
  76. prom.CacheMiss.Incr("TopArc")
  77. res, err = d.RawTopArc(c, id)
  78. if err != nil {
  79. return
  80. }
  81. miss := res
  82. if miss == nil {
  83. miss = &model.AidReason{Aid: -1}
  84. }
  85. if !addCache {
  86. return
  87. }
  88. d.cache.Do(c, func(c context.Context) {
  89. d.AddCacheTopArc(c, id, miss)
  90. })
  91. return
  92. }
  93. // Masterpiece get data from cache if miss will call source method, then add to cache.
  94. func (d *Dao) Masterpiece(c context.Context, id int64) (res *model.AidReasons, err error) {
  95. addCache := true
  96. res, err = d.CacheMasterpiece(c, id)
  97. if err != nil {
  98. addCache = false
  99. err = nil
  100. }
  101. defer func() {
  102. if len(res.List) == 1 && res.List[0].Aid == -1 {
  103. res = nil
  104. }
  105. }()
  106. if res != nil {
  107. prom.CacheHit.Incr("Masterpiece")
  108. return
  109. }
  110. prom.CacheMiss.Incr("Masterpiece")
  111. res, err = d.RawMasterpiece(c, id)
  112. if err != nil {
  113. return
  114. }
  115. miss := res
  116. if miss == nil {
  117. miss = &model.AidReasons{List: []*model.AidReason{{Aid: -1}}}
  118. }
  119. if !addCache {
  120. return
  121. }
  122. d.cache.Do(c, func(c context.Context) {
  123. d.AddCacheMasterpiece(c, id, miss)
  124. })
  125. return
  126. }
  127. // Theme get data from cache if miss will call source method, then add to cache.
  128. func (d *Dao) Theme(c context.Context, id int64) (res *model.ThemeDetails, err error) {
  129. addCache := true
  130. res, err = d.CacheTheme(c, id)
  131. if err != nil {
  132. addCache = false
  133. err = nil
  134. }
  135. defer func() {
  136. if len(res.List) == 1 && res.List[0].ID == -1 {
  137. res = nil
  138. }
  139. }()
  140. if res != nil {
  141. prom.CacheHit.Incr("Theme")
  142. return
  143. }
  144. prom.CacheMiss.Incr("Theme")
  145. res, err = d.RawTheme(c, id)
  146. if err != nil {
  147. return
  148. }
  149. miss := res
  150. if miss == nil {
  151. miss = &model.ThemeDetails{List: []*model.ThemeDetail{{ID: -1}}}
  152. }
  153. if !addCache {
  154. return
  155. }
  156. d.cache.Do(c, func(c context.Context) {
  157. d.AddCacheTheme(c, id, miss)
  158. })
  159. return
  160. }
  161. // TopDynamic get data from cache if miss will call source method, then add to cache.
  162. func (d *Dao) TopDynamic(c context.Context, id int64) (res int64, err error) {
  163. addCache := true
  164. res, err = d.CacheTopDynamic(c, id)
  165. if err != nil {
  166. addCache = false
  167. err = nil
  168. }
  169. defer func() {
  170. if res == -1 {
  171. res = 0
  172. }
  173. }()
  174. if res != 0 {
  175. prom.CacheHit.Incr("TopDynamic")
  176. return
  177. }
  178. prom.CacheMiss.Incr("TopDynamic")
  179. res, err = d.RawTopDynamic(c, id)
  180. if err != nil {
  181. return
  182. }
  183. miss := res
  184. if miss == 0 {
  185. miss = -1
  186. }
  187. if !addCache {
  188. return
  189. }
  190. d.cache.Do(c, func(c context.Context) {
  191. d.AddCacheTopDynamic(c, id, miss)
  192. })
  193. return
  194. }