dao.cache.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. // Code generated by $GOPATH/src/go-common/app/tool/cache/gen. DO NOT EDIT.
  2. /*
  3. Package like is a generated cache proxy package.
  4. It is generated from:
  5. type _cache interface {
  6. // cache: -sync=true
  7. Like(c context.Context, id int64) (*likemdl.Item, error)
  8. // cache: -sync=true
  9. Likes(c context.Context, ids []int64) (map[int64]*likemdl.Item, error)
  10. // cache: -sync=true
  11. ActSubject(c context.Context, id int64) (*likemdl.SubjectItem, error)
  12. //cache: -sync=true -nullcache=-1 -check_null_code=$==-1
  13. LikeMissionBuff(ctx context.Context, sid int64, mid int64) (res int64, err error)
  14. //cache: -sync=true
  15. MissionGroupItems(ctx context.Context, lids []int64) (map[int64]*likemdl.MissionGroup, error)
  16. //cache: -sync=true -nullcache=-1 -check_null_code=$!=nil&&$==-1
  17. ActMission(ctx context.Context, sid int64, lid int64, mid int64) (res int64, err error)
  18. //cache:-sync=true
  19. ActLikeAchieves(ctx context.Context, sid int64) (res *likemdl.Achievements, err error)
  20. //cache:-sync=true
  21. ActMissionFriends(ctx context.Context, sid int64, lid int64) (res *likemdl.ActMissionGroups, err error)
  22. //cache:-sync=true
  23. ActUserAchieve(ctx context.Context, id int64) (res *likemdl.ActLikeUserAchievement, err error)
  24. // cache
  25. MatchSubjects(c context.Context, ids []int64) (map[int64]*likemdl.Object, error)
  26. // cache:-sync=true
  27. LikeContent(c context.Context, ids []int64) (map[int64]*likemdl.LikeContent, error)
  28. // cache
  29. SourceItemData(c context.Context, sid int64) ([]int64, error)
  30. // cache:-sync=true
  31. ActSubjectProtocol(c context.Context, sid int64) (res *likemdl.ActSubjectProtocol, err error)
  32. }
  33. */
  34. package like
  35. import (
  36. "context"
  37. likemdl "go-common/app/interface/main/activity/model/like"
  38. "go-common/library/stat/prom"
  39. )
  40. var _ _cache
  41. // Like get data from cache if miss will call source method, then add to cache.
  42. func (d *Dao) Like(c context.Context, id int64) (res *likemdl.Item, err error) {
  43. addCache := true
  44. res, err = d.CacheLike(c, id)
  45. if err != nil {
  46. addCache = false
  47. err = nil
  48. }
  49. if res != nil {
  50. prom.CacheHit.Incr("Like")
  51. return
  52. }
  53. prom.CacheMiss.Incr("Like")
  54. res, err = d.RawLike(c, id)
  55. if err != nil {
  56. return
  57. }
  58. miss := res
  59. if !addCache {
  60. return
  61. }
  62. d.AddCacheLike(c, id, miss)
  63. return
  64. }
  65. // Likes get data from cache if miss will call source method, then add to cache.
  66. func (d *Dao) Likes(c context.Context, keys []int64) (res map[int64]*likemdl.Item, err error) {
  67. if len(keys) == 0 {
  68. return
  69. }
  70. addCache := true
  71. if res, err = d.CacheLikes(c, keys); err != nil {
  72. addCache = false
  73. res = nil
  74. err = nil
  75. }
  76. var miss []int64
  77. for _, key := range keys {
  78. if (res == nil) || (res[key] == nil) {
  79. miss = append(miss, key)
  80. }
  81. }
  82. prom.CacheHit.Add("Likes", int64(len(keys)-len(miss)))
  83. missLen := len(miss)
  84. if missLen == 0 {
  85. return
  86. }
  87. var missData map[int64]*likemdl.Item
  88. prom.CacheMiss.Add("Likes", int64(len(miss)))
  89. missData, err = d.RawLikes(c, miss)
  90. if res == nil {
  91. res = make(map[int64]*likemdl.Item, len(keys))
  92. }
  93. for k, v := range missData {
  94. res[k] = v
  95. }
  96. if err != nil {
  97. return
  98. }
  99. if !addCache {
  100. return
  101. }
  102. d.AddCacheLikes(c, missData)
  103. return
  104. }
  105. // ActSubject get data from cache if miss will call source method, then add to cache.
  106. func (d *Dao) ActSubject(c context.Context, id int64) (res *likemdl.SubjectItem, err error) {
  107. addCache := true
  108. res, err = d.CacheActSubject(c, id)
  109. if err != nil {
  110. addCache = false
  111. err = nil
  112. }
  113. if res != nil {
  114. prom.CacheHit.Incr("ActSubject")
  115. return
  116. }
  117. prom.CacheMiss.Incr("ActSubject")
  118. res, err = d.RawActSubject(c, id)
  119. if err != nil {
  120. return
  121. }
  122. miss := res
  123. if !addCache {
  124. return
  125. }
  126. d.AddCacheActSubject(c, id, miss)
  127. return
  128. }
  129. // LikeMissionBuff get data from cache if miss will call source method, then add to cache.
  130. func (d *Dao) LikeMissionBuff(c context.Context, id int64, mid int64) (res int64, err error) {
  131. addCache := true
  132. res, err = d.CacheLikeMissionBuff(c, id, mid)
  133. if err != nil {
  134. addCache = false
  135. err = nil
  136. }
  137. defer func() {
  138. if res == -1 {
  139. res = 0
  140. }
  141. }()
  142. if res != 0 {
  143. prom.CacheHit.Incr("LikeMissionBuff")
  144. return
  145. }
  146. prom.CacheMiss.Incr("LikeMissionBuff")
  147. res, err = d.RawLikeMissionBuff(c, id, mid)
  148. if err != nil {
  149. return
  150. }
  151. miss := res
  152. if miss == 0 {
  153. miss = -1
  154. }
  155. if !addCache {
  156. return
  157. }
  158. d.AddCacheLikeMissionBuff(c, id, miss, mid)
  159. return
  160. }
  161. // MissionGroupItems get data from cache if miss will call source method, then add to cache.
  162. func (d *Dao) MissionGroupItems(c context.Context, keys []int64) (res map[int64]*likemdl.MissionGroup, err error) {
  163. if len(keys) == 0 {
  164. return
  165. }
  166. addCache := true
  167. if res, err = d.CacheMissionGroupItems(c, keys); err != nil {
  168. addCache = false
  169. res = nil
  170. err = nil
  171. }
  172. var miss []int64
  173. for _, key := range keys {
  174. if (res == nil) || (res[key] == nil) {
  175. miss = append(miss, key)
  176. }
  177. }
  178. prom.CacheHit.Add("MissionGroupItems", int64(len(keys)-len(miss)))
  179. missLen := len(miss)
  180. if missLen == 0 {
  181. return
  182. }
  183. var missData map[int64]*likemdl.MissionGroup
  184. prom.CacheMiss.Add("MissionGroupItems", int64(len(miss)))
  185. missData, err = d.RawMissionGroupItems(c, miss)
  186. if res == nil {
  187. res = make(map[int64]*likemdl.MissionGroup, len(keys))
  188. }
  189. for k, v := range missData {
  190. res[k] = v
  191. }
  192. if err != nil {
  193. return
  194. }
  195. if !addCache {
  196. return
  197. }
  198. d.AddCacheMissionGroupItems(c, missData)
  199. return
  200. }
  201. // ActMission get data from cache if miss will call source method, then add to cache.
  202. func (d *Dao) ActMission(c context.Context, id int64, lid int64, mid int64) (res int64, err error) {
  203. addCache := true
  204. res, err = d.CacheActMission(c, id, lid, mid)
  205. if err != nil {
  206. addCache = false
  207. err = nil
  208. }
  209. defer func() {
  210. if res == -1 {
  211. res = 0
  212. }
  213. }()
  214. if res != 0 {
  215. prom.CacheHit.Incr("ActMission")
  216. return
  217. }
  218. prom.CacheMiss.Incr("ActMission")
  219. res, err = d.RawActMission(c, id, lid, mid)
  220. if err != nil {
  221. return
  222. }
  223. miss := res
  224. if miss == 0 {
  225. miss = -1
  226. }
  227. if !addCache {
  228. return
  229. }
  230. d.AddCacheActMission(c, id, miss, lid, mid)
  231. return
  232. }
  233. // ActLikeAchieves get data from cache if miss will call source method, then add to cache.
  234. func (d *Dao) ActLikeAchieves(c context.Context, id int64) (res *likemdl.Achievements, err error) {
  235. addCache := true
  236. res, err = d.CacheActLikeAchieves(c, id)
  237. if err != nil {
  238. addCache = false
  239. err = nil
  240. }
  241. if res != nil {
  242. prom.CacheHit.Incr("ActLikeAchieves")
  243. return
  244. }
  245. prom.CacheMiss.Incr("ActLikeAchieves")
  246. res, err = d.RawActLikeAchieves(c, id)
  247. if err != nil {
  248. return
  249. }
  250. miss := res
  251. if !addCache {
  252. return
  253. }
  254. d.AddCacheActLikeAchieves(c, id, miss)
  255. return
  256. }
  257. // ActMissionFriends get data from cache if miss will call source method, then add to cache.
  258. func (d *Dao) ActMissionFriends(c context.Context, id int64, lid int64) (res *likemdl.ActMissionGroups, err error) {
  259. addCache := true
  260. res, err = d.CacheActMissionFriends(c, id, lid)
  261. if err != nil {
  262. addCache = false
  263. err = nil
  264. }
  265. if res != nil {
  266. prom.CacheHit.Incr("ActMissionFriends")
  267. return
  268. }
  269. prom.CacheMiss.Incr("ActMissionFriends")
  270. res, err = d.RawActMissionFriends(c, id, lid)
  271. if err != nil {
  272. return
  273. }
  274. miss := res
  275. if !addCache {
  276. return
  277. }
  278. d.AddCacheActMissionFriends(c, id, miss, lid)
  279. return
  280. }
  281. // ActUserAchieve get data from cache if miss will call source method, then add to cache.
  282. func (d *Dao) ActUserAchieve(c context.Context, id int64) (res *likemdl.ActLikeUserAchievement, err error) {
  283. addCache := true
  284. res, err = d.CacheActUserAchieve(c, id)
  285. if err != nil {
  286. addCache = false
  287. err = nil
  288. }
  289. if res != nil {
  290. prom.CacheHit.Incr("ActUserAchieve")
  291. return
  292. }
  293. prom.CacheMiss.Incr("ActUserAchieve")
  294. res, err = d.RawActUserAchieve(c, id)
  295. if err != nil {
  296. return
  297. }
  298. miss := res
  299. if !addCache {
  300. return
  301. }
  302. d.AddCacheActUserAchieve(c, id, miss)
  303. return
  304. }
  305. // MatchSubjects get data from cache if miss will call source method, then add to cache.
  306. func (d *Dao) MatchSubjects(c context.Context, keys []int64) (res map[int64]*likemdl.Object, err error) {
  307. if len(keys) == 0 {
  308. return
  309. }
  310. addCache := true
  311. if res, err = d.CacheMatchSubjects(c, keys); err != nil {
  312. addCache = false
  313. res = nil
  314. err = nil
  315. }
  316. var miss []int64
  317. for _, key := range keys {
  318. if (res == nil) || (res[key] == nil) {
  319. miss = append(miss, key)
  320. }
  321. }
  322. prom.CacheHit.Add("MatchSubjects", int64(len(keys)-len(miss)))
  323. missLen := len(miss)
  324. if missLen == 0 {
  325. return
  326. }
  327. var missData map[int64]*likemdl.Object
  328. prom.CacheMiss.Add("MatchSubjects", int64(len(miss)))
  329. missData, err = d.RawMatchSubjects(c, miss)
  330. if res == nil {
  331. res = make(map[int64]*likemdl.Object, len(keys))
  332. }
  333. for k, v := range missData {
  334. res[k] = v
  335. }
  336. if err != nil {
  337. return
  338. }
  339. if !addCache {
  340. return
  341. }
  342. d.cache.Do(c, func(c context.Context) {
  343. d.AddCacheMatchSubjects(c, missData)
  344. })
  345. return
  346. }
  347. // LikeContent get data from cache if miss will call source method, then add to cache.
  348. func (d *Dao) LikeContent(c context.Context, keys []int64) (res map[int64]*likemdl.LikeContent, err error) {
  349. if len(keys) == 0 {
  350. return
  351. }
  352. addCache := true
  353. if res, err = d.CacheLikeContent(c, keys); err != nil {
  354. addCache = false
  355. res = nil
  356. err = nil
  357. }
  358. var miss []int64
  359. for _, key := range keys {
  360. if (res == nil) || (res[key] == nil) {
  361. miss = append(miss, key)
  362. }
  363. }
  364. prom.CacheHit.Add("LikeContent", int64(len(keys)-len(miss)))
  365. missLen := len(miss)
  366. if missLen == 0 {
  367. return
  368. }
  369. var missData map[int64]*likemdl.LikeContent
  370. prom.CacheMiss.Add("LikeContent", int64(len(miss)))
  371. missData, err = d.RawLikeContent(c, miss)
  372. if res == nil {
  373. res = make(map[int64]*likemdl.LikeContent, len(keys))
  374. }
  375. for k, v := range missData {
  376. res[k] = v
  377. }
  378. if err != nil {
  379. return
  380. }
  381. if !addCache {
  382. return
  383. }
  384. d.AddCacheLikeContent(c, missData)
  385. return
  386. }
  387. // SourceItemData get data from cache if miss will call source method, then add to cache.
  388. func (d *Dao) SourceItemData(c context.Context, id int64) (res []int64, err error) {
  389. addCache := true
  390. res, err = d.CacheSourceItemData(c, id)
  391. if err != nil {
  392. addCache = false
  393. err = nil
  394. }
  395. if len(res) != 0 {
  396. prom.CacheHit.Incr("SourceItemData")
  397. return
  398. }
  399. prom.CacheMiss.Incr("SourceItemData")
  400. res, err = d.RawSourceItemData(c, id)
  401. if err != nil {
  402. return
  403. }
  404. miss := res
  405. if !addCache {
  406. return
  407. }
  408. d.cache.Do(c, func(c context.Context) {
  409. d.AddCacheSourceItemData(c, id, miss)
  410. })
  411. return
  412. }
  413. // ActSubjectProtocol get data from cache if miss will call source method, then add to cache.
  414. func (d *Dao) ActSubjectProtocol(c context.Context, id int64) (res *likemdl.ActSubjectProtocol, err error) {
  415. addCache := true
  416. res, err = d.CacheActSubjectProtocol(c, id)
  417. if err != nil {
  418. addCache = false
  419. err = nil
  420. }
  421. if res != nil {
  422. prom.CacheHit.Incr("ActSubjectProtocol")
  423. return
  424. }
  425. prom.CacheMiss.Incr("ActSubjectProtocol")
  426. res, err = d.RawActSubjectProtocol(c, id)
  427. if err != nil {
  428. return
  429. }
  430. miss := res
  431. if !addCache {
  432. return
  433. }
  434. d.AddCacheActSubjectProtocol(c, id, miss)
  435. return
  436. }