dao.cache.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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
  7. EpContests(c context.Context, ids []int64) (map[int64]*model.Contest, error)
  8. // cache
  9. EpSeasons(c context.Context, ids []int64) (map[int64]*model.Season, error)
  10. // cache
  11. EpTeams(c context.Context, ids []int64) (map[int64]*model.Team, error)
  12. // cache
  13. EpContestsData(c context.Context, ids []int64) (map[int64][]*model.ContestsData, error)
  14. }
  15. */
  16. package dao
  17. import (
  18. "context"
  19. "go-common/app/interface/main/esports/model"
  20. "go-common/library/stat/prom"
  21. )
  22. var _ _cache
  23. // EpContests get data from cache if miss will call source method, then add to cache.
  24. func (d *Dao) EpContests(c context.Context, keys []int64) (res map[int64]*model.Contest, err error) {
  25. if len(keys) == 0 {
  26. return
  27. }
  28. addCache := true
  29. if res, err = d.CacheEpContests(c, keys); err != nil {
  30. addCache = false
  31. res = nil
  32. err = nil
  33. }
  34. var miss []int64
  35. for _, key := range keys {
  36. if (res == nil) || (res[key] == nil) {
  37. miss = append(miss, key)
  38. }
  39. }
  40. prom.CacheHit.Add("EpContests", int64(len(keys)-len(miss)))
  41. missLen := len(miss)
  42. if missLen == 0 {
  43. return
  44. }
  45. var missData map[int64]*model.Contest
  46. prom.CacheMiss.Add("EpContests", int64(len(miss)))
  47. missData, err = d.RawEpContests(c, miss)
  48. if res == nil {
  49. res = make(map[int64]*model.Contest, len(keys))
  50. }
  51. for k, v := range missData {
  52. res[k] = v
  53. }
  54. if err != nil {
  55. return
  56. }
  57. if !addCache {
  58. return
  59. }
  60. d.cache.Do(c, func(c context.Context) {
  61. d.AddCacheEpContests(c, missData)
  62. })
  63. return
  64. }
  65. // EpSeasons get data from cache if miss will call source method, then add to cache.
  66. func (d *Dao) EpSeasons(c context.Context, keys []int64) (res map[int64]*model.Season, err error) {
  67. if len(keys) == 0 {
  68. return
  69. }
  70. addCache := true
  71. if res, err = d.CacheEpSeasons(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("EpSeasons", int64(len(keys)-len(miss)))
  83. missLen := len(miss)
  84. if missLen == 0 {
  85. return
  86. }
  87. var missData map[int64]*model.Season
  88. prom.CacheMiss.Add("EpSeasons", int64(len(miss)))
  89. missData, err = d.RawEpSeasons(c, miss)
  90. if res == nil {
  91. res = make(map[int64]*model.Season, 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.cache.Do(c, func(c context.Context) {
  103. d.AddCacheEpSeasons(c, missData)
  104. })
  105. return
  106. }
  107. // EpTeams get data from cache if miss will call source method, then add to cache.
  108. func (d *Dao) EpTeams(c context.Context, keys []int64) (res map[int64]*model.Team, err error) {
  109. if len(keys) == 0 {
  110. return
  111. }
  112. addCache := true
  113. if res, err = d.CacheEpTeams(c, keys); err != nil {
  114. addCache = false
  115. res = nil
  116. err = nil
  117. }
  118. var miss []int64
  119. for _, key := range keys {
  120. if (res == nil) || (res[key] == nil) {
  121. miss = append(miss, key)
  122. }
  123. }
  124. prom.CacheHit.Add("EpTeams", int64(len(keys)-len(miss)))
  125. missLen := len(miss)
  126. if missLen == 0 {
  127. return
  128. }
  129. var missData map[int64]*model.Team
  130. prom.CacheMiss.Add("EpTeams", int64(len(miss)))
  131. missData, err = d.RawEpTeams(c, miss)
  132. if res == nil {
  133. res = make(map[int64]*model.Team, len(keys))
  134. }
  135. for k, v := range missData {
  136. res[k] = v
  137. }
  138. if err != nil {
  139. return
  140. }
  141. if !addCache {
  142. return
  143. }
  144. d.cache.Do(c, func(c context.Context) {
  145. d.AddCacheEpTeams(c, missData)
  146. })
  147. return
  148. }