dao.cache.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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.Item{ID:-1} -check_null_code=$!=nil&&$.ID==-1
  7. Items(c context.Context, pid []int64) (info map[int64]*model.Item, err error)
  8. // cache: -nullcache=&model.ItemDetail{ProjectID:-1} -check_null_code=$!=nil&&$.ProjectID==-1
  9. ItemDetails(c context.Context, pid []int64) (details map[int64]*model.ItemDetail, err error)
  10. // cache: -nullcache=[]*model.TicketInfo{{TicketPrice:model.TicketPrice{ProjectID:-1}}} -check_null_code=len($)==1&&$[0].ProjectID==-1
  11. TkListByItem(c context.Context, pid []int64) (info map[int64][]*model.TicketInfo, err error)
  12. // cache: -nullcache=&model.Venue{ID:-1} -check_null_code=$!=nil&&$.ID==-1
  13. Venues(c context.Context, id []int64) (venues map[int64]*model.Venue, err error)
  14. // cache: -nullcache=&model.Place{ID:-1} -check_null_code=$!=nil&&$.ID==-1
  15. Place(c context.Context, id int64) (place *model.Place, err error)
  16. // cache: -nullcache=[]*model.Screen{{ProjectID:-1}} -check_null_code=len($)==1&&$[0].ProjectID==-1
  17. ScListByItem(c context.Context, pid []int64) (info map[int64][]*model.Screen, err error)
  18. // cache: -nullcache=&model.Screen{ProjectID:-1} -check_null_code=$!=nil&&$.ProjectID==-1
  19. ScList(c context.Context, sids []int64) (info map[int64]*model.Screen, err error)
  20. // cache: -nullcache=&model.TicketInfo{TicketPrice:model.TicketPrice{ProjectID:-1}} -check_null_code=$!=nil&&$.ProjectID==-1
  21. TkList(c context.Context, tids []int64) (info map[int64]*model.TicketInfo, err error)
  22. }
  23. */
  24. package dao
  25. import (
  26. "context"
  27. "go-common/app/service/openplatform/ticket-item/model"
  28. "go-common/library/stat/prom"
  29. )
  30. var _ _cache
  31. // Items get data from cache if miss will call source method, then add to cache.
  32. func (d *Dao) Items(c context.Context, keys []int64) (res map[int64]*model.Item, err error) {
  33. if len(keys) == 0 {
  34. return
  35. }
  36. addCache := true
  37. if res, err = d.CacheItems(c, keys); err != nil {
  38. addCache = false
  39. res = nil
  40. err = nil
  41. }
  42. var miss []int64
  43. for _, key := range keys {
  44. if (res == nil) || (res[key] == nil) {
  45. miss = append(miss, key)
  46. }
  47. }
  48. prom.CacheHit.Add("Items", int64(len(keys)-len(miss)))
  49. for k, v := range res {
  50. if v != nil && v.ID == -1 {
  51. delete(res, k)
  52. }
  53. }
  54. missLen := len(miss)
  55. if missLen == 0 {
  56. return
  57. }
  58. var missData map[int64]*model.Item
  59. prom.CacheMiss.Add("Items", int64(len(miss)))
  60. missData, err = d.RawItems(c, miss)
  61. if res == nil {
  62. res = make(map[int64]*model.Item, len(keys))
  63. }
  64. for k, v := range missData {
  65. res[k] = v
  66. }
  67. if err != nil {
  68. return
  69. }
  70. for _, key := range miss {
  71. if res[key] == nil {
  72. missData[key] = &model.Item{ID: -1}
  73. }
  74. }
  75. if !addCache {
  76. return
  77. }
  78. d.cache.Do(c, func(c context.Context) {
  79. d.AddCacheItems(c, missData)
  80. })
  81. return
  82. }
  83. // ItemDetails get data from cache if miss will call source method, then add to cache.
  84. func (d *Dao) ItemDetails(c context.Context, keys []int64) (res map[int64]*model.ItemDetail, err error) {
  85. if len(keys) == 0 {
  86. return
  87. }
  88. addCache := true
  89. if res, err = d.CacheItemDetails(c, keys); err != nil {
  90. addCache = false
  91. res = nil
  92. err = nil
  93. }
  94. var miss []int64
  95. for _, key := range keys {
  96. if (res == nil) || (res[key] == nil) {
  97. miss = append(miss, key)
  98. }
  99. }
  100. prom.CacheHit.Add("ItemDetails", int64(len(keys)-len(miss)))
  101. for k, v := range res {
  102. if v != nil && v.ProjectID == -1 {
  103. delete(res, k)
  104. }
  105. }
  106. missLen := len(miss)
  107. if missLen == 0 {
  108. return
  109. }
  110. var missData map[int64]*model.ItemDetail
  111. prom.CacheMiss.Add("ItemDetails", int64(len(miss)))
  112. missData, err = d.RawItemDetails(c, miss)
  113. if res == nil {
  114. res = make(map[int64]*model.ItemDetail, len(keys))
  115. }
  116. for k, v := range missData {
  117. res[k] = v
  118. }
  119. if err != nil {
  120. return
  121. }
  122. for _, key := range miss {
  123. if res[key] == nil {
  124. missData[key] = &model.ItemDetail{ProjectID: -1}
  125. }
  126. }
  127. if !addCache {
  128. return
  129. }
  130. d.cache.Do(c, func(c context.Context) {
  131. d.AddCacheItemDetails(c, missData)
  132. })
  133. return
  134. }
  135. // TkListByItem get data from cache if miss will call source method, then add to cache.
  136. func (d *Dao) TkListByItem(c context.Context, keys []int64) (res map[int64][]*model.TicketInfo, err error) {
  137. if len(keys) == 0 {
  138. return
  139. }
  140. addCache := true
  141. if res, err = d.CacheTkListByItem(c, keys); err != nil {
  142. addCache = false
  143. res = nil
  144. err = nil
  145. }
  146. var miss []int64
  147. for _, key := range keys {
  148. if (res == nil) || (len(res[key]) == 0) {
  149. miss = append(miss, key)
  150. }
  151. }
  152. prom.CacheHit.Add("TkListByItem", int64(len(keys)-len(miss)))
  153. for k, v := range res {
  154. if len(v) == 1 && v[0].ProjectID == -1 {
  155. delete(res, k)
  156. }
  157. }
  158. missLen := len(miss)
  159. if missLen == 0 {
  160. return
  161. }
  162. var missData map[int64][]*model.TicketInfo
  163. prom.CacheMiss.Add("TkListByItem", int64(len(miss)))
  164. missData, err = d.RawTkListByItem(c, miss)
  165. if res == nil {
  166. res = make(map[int64][]*model.TicketInfo, len(keys))
  167. }
  168. for k, v := range missData {
  169. res[k] = v
  170. }
  171. if err != nil {
  172. return
  173. }
  174. for _, key := range miss {
  175. if len(res[key]) == 0 {
  176. missData[key] = []*model.TicketInfo{{TicketPrice: model.TicketPrice{ProjectID: -1}}}
  177. }
  178. }
  179. if !addCache {
  180. return
  181. }
  182. d.cache.Do(c, func(c context.Context) {
  183. d.AddCacheTkListByItem(c, missData)
  184. })
  185. return
  186. }
  187. // Venues get data from cache if miss will call source method, then add to cache.
  188. func (d *Dao) Venues(c context.Context, keys []int64) (res map[int64]*model.Venue, err error) {
  189. if len(keys) == 0 {
  190. return
  191. }
  192. addCache := true
  193. if res, err = d.CacheVenues(c, keys); err != nil {
  194. addCache = false
  195. res = nil
  196. err = nil
  197. }
  198. var miss []int64
  199. for _, key := range keys {
  200. if (res == nil) || (res[key] == nil) {
  201. miss = append(miss, key)
  202. }
  203. }
  204. prom.CacheHit.Add("Venues", int64(len(keys)-len(miss)))
  205. for k, v := range res {
  206. if v != nil && v.ID == -1 {
  207. delete(res, k)
  208. }
  209. }
  210. missLen := len(miss)
  211. if missLen == 0 {
  212. return
  213. }
  214. var missData map[int64]*model.Venue
  215. prom.CacheMiss.Add("Venues", int64(len(miss)))
  216. missData, err = d.RawVenues(c, miss)
  217. if res == nil {
  218. res = make(map[int64]*model.Venue, len(keys))
  219. }
  220. for k, v := range missData {
  221. res[k] = v
  222. }
  223. if err != nil {
  224. return
  225. }
  226. for _, key := range miss {
  227. if res[key] == nil {
  228. missData[key] = &model.Venue{ID: -1}
  229. }
  230. }
  231. if !addCache {
  232. return
  233. }
  234. d.cache.Do(c, func(c context.Context) {
  235. d.AddCacheVenues(c, missData)
  236. })
  237. return
  238. }
  239. // Place get data from cache if miss will call source method, then add to cache.
  240. func (d *Dao) Place(c context.Context, id int64) (res *model.Place, err error) {
  241. addCache := true
  242. res, err = d.CachePlace(c, id)
  243. if err != nil {
  244. addCache = false
  245. err = nil
  246. }
  247. defer func() {
  248. if res != nil && res.ID == -1 {
  249. res = nil
  250. }
  251. }()
  252. if res != nil {
  253. prom.CacheHit.Incr("Place")
  254. return
  255. }
  256. prom.CacheMiss.Incr("Place")
  257. res, err = d.RawPlace(c, id)
  258. if err != nil {
  259. return
  260. }
  261. miss := res
  262. if miss == nil {
  263. miss = &model.Place{ID: -1}
  264. }
  265. if !addCache {
  266. return
  267. }
  268. d.cache.Do(c, func(c context.Context) {
  269. d.AddCachePlace(c, id, miss)
  270. })
  271. return
  272. }
  273. // ScListByItem get data from cache if miss will call source method, then add to cache.
  274. func (d *Dao) ScListByItem(c context.Context, keys []int64) (res map[int64][]*model.Screen, err error) {
  275. if len(keys) == 0 {
  276. return
  277. }
  278. addCache := true
  279. if res, err = d.CacheScListByItem(c, keys); err != nil {
  280. addCache = false
  281. res = nil
  282. err = nil
  283. }
  284. var miss []int64
  285. for _, key := range keys {
  286. if (res == nil) || (len(res[key]) == 0) {
  287. miss = append(miss, key)
  288. }
  289. }
  290. prom.CacheHit.Add("ScListByItem", int64(len(keys)-len(miss)))
  291. for k, v := range res {
  292. if len(v) == 1 && v[0].ProjectID == -1 {
  293. delete(res, k)
  294. }
  295. }
  296. missLen := len(miss)
  297. if missLen == 0 {
  298. return
  299. }
  300. var missData map[int64][]*model.Screen
  301. prom.CacheMiss.Add("ScListByItem", int64(len(miss)))
  302. missData, err = d.RawScListByItem(c, miss)
  303. if res == nil {
  304. res = make(map[int64][]*model.Screen, len(keys))
  305. }
  306. for k, v := range missData {
  307. res[k] = v
  308. }
  309. if err != nil {
  310. return
  311. }
  312. for _, key := range miss {
  313. if len(res[key]) == 0 {
  314. missData[key] = []*model.Screen{{ProjectID: -1}}
  315. }
  316. }
  317. if !addCache {
  318. return
  319. }
  320. d.cache.Do(c, func(c context.Context) {
  321. d.AddCacheScListByItem(c, missData)
  322. })
  323. return
  324. }
  325. // ScList get data from cache if miss will call source method, then add to cache.
  326. func (d *Dao) ScList(c context.Context, keys []int64) (res map[int64]*model.Screen, err error) {
  327. if len(keys) == 0 {
  328. return
  329. }
  330. addCache := true
  331. if res, err = d.CacheScList(c, keys); err != nil {
  332. addCache = false
  333. res = nil
  334. err = nil
  335. }
  336. var miss []int64
  337. for _, key := range keys {
  338. if (res == nil) || (res[key] == nil) {
  339. miss = append(miss, key)
  340. }
  341. }
  342. prom.CacheHit.Add("ScList", int64(len(keys)-len(miss)))
  343. for k, v := range res {
  344. if v != nil && v.ProjectID == -1 {
  345. delete(res, k)
  346. }
  347. }
  348. missLen := len(miss)
  349. if missLen == 0 {
  350. return
  351. }
  352. var missData map[int64]*model.Screen
  353. prom.CacheMiss.Add("ScList", int64(len(miss)))
  354. missData, err = d.RawScList(c, miss)
  355. if res == nil {
  356. res = make(map[int64]*model.Screen, len(keys))
  357. }
  358. for k, v := range missData {
  359. res[k] = v
  360. }
  361. if err != nil {
  362. return
  363. }
  364. for _, key := range miss {
  365. if res[key] == nil {
  366. missData[key] = &model.Screen{ProjectID: -1}
  367. }
  368. }
  369. if !addCache {
  370. return
  371. }
  372. d.cache.Do(c, func(c context.Context) {
  373. d.AddCacheScList(c, missData)
  374. })
  375. return
  376. }
  377. // TkList get data from cache if miss will call source method, then add to cache.
  378. func (d *Dao) TkList(c context.Context, keys []int64) (res map[int64]*model.TicketInfo, err error) {
  379. if len(keys) == 0 {
  380. return
  381. }
  382. addCache := true
  383. if res, err = d.CacheTkList(c, keys); err != nil {
  384. addCache = false
  385. res = nil
  386. err = nil
  387. }
  388. var miss []int64
  389. for _, key := range keys {
  390. if (res == nil) || (res[key] == nil) {
  391. miss = append(miss, key)
  392. }
  393. }
  394. prom.CacheHit.Add("TkList", int64(len(keys)-len(miss)))
  395. for k, v := range res {
  396. if v != nil && v.ProjectID == -1 {
  397. delete(res, k)
  398. }
  399. }
  400. missLen := len(miss)
  401. if missLen == 0 {
  402. return
  403. }
  404. var missData map[int64]*model.TicketInfo
  405. prom.CacheMiss.Add("TkList", int64(len(miss)))
  406. missData, err = d.RawTkList(c, miss)
  407. if res == nil {
  408. res = make(map[int64]*model.TicketInfo, len(keys))
  409. }
  410. for k, v := range missData {
  411. res[k] = v
  412. }
  413. if err != nil {
  414. return
  415. }
  416. for _, key := range miss {
  417. if res[key] == nil {
  418. missData[key] = &model.TicketInfo{TicketPrice: model.TicketPrice{ProjectID: -1}}
  419. }
  420. }
  421. if !addCache {
  422. return
  423. }
  424. d.cache.Do(c, func(c context.Context) {
  425. d.AddCacheTkList(c, missData)
  426. })
  427. return
  428. }