cache.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package like
  2. import (
  3. "context"
  4. "fmt"
  5. likemdl "go-common/app/interface/main/activity/model/like"
  6. )
  7. // likeKey likes table line cache
  8. func likeKey(id int64) string {
  9. return fmt.Sprintf("go_l_id_%d", id)
  10. }
  11. // actSubjectKey act_subject table line cache .
  12. func actSubjectKey(id int64) string {
  13. return fmt.Sprintf("go_s_id_%d", id)
  14. }
  15. // actSubjectMaxIDKey act_subject table max id cache
  16. func actSubjectMaxIDKey() string {
  17. return "go_sub_id_max"
  18. }
  19. // likeMaxIDKey likes table max id cache
  20. func likeMaxIDKey() string {
  21. return "go_like_id_max"
  22. }
  23. // likeMissionBuffKey .
  24. func likeMissionBuffKey(sid, mid int64) string {
  25. return fmt.Sprintf("go_l_m_a_%d_%d", sid, mid)
  26. }
  27. // likeMissionGroupIDkey .
  28. func likeMissionGroupIDkey(lid int64) string {
  29. return fmt.Sprintf("go_l_m_g_id_%d", lid)
  30. }
  31. // likeActMissionKey flag has buff or not.
  32. func likeActMissionKey(sid, lid, mid int64) string {
  33. return fmt.Sprintf("go:b-a:m:l:%d:%d:%d", sid, lid, mid)
  34. }
  35. // actAchieveKey .
  36. func actAchieveKey(sid int64) string {
  37. return fmt.Sprintf("go:a:achs:%d", sid)
  38. }
  39. // actMissionFriendsKey .
  40. func actMissionFriendsKey(sid, lid int64) string {
  41. return fmt.Sprintf("go:a:m:frd:%d:%d", sid, lid)
  42. }
  43. // actUserAchieveKey .
  44. func actUserAchieveKey(id int64) string {
  45. return fmt.Sprintf("go:a:u:m:%d", id)
  46. }
  47. // actUserAchieveAwardKey .
  48. func actUserAchieveAwardKey(id int64) string {
  49. return fmt.Sprintf("go:a:u:a:%d", id)
  50. }
  51. func subjectStatKey(sid int64) string {
  52. return fmt.Sprintf("ob_s_%d", sid)
  53. }
  54. func viewRankKey(sid int64) string {
  55. return fmt.Sprintf("v_r_%d", sid)
  56. }
  57. func likeContentKey(lid int64) string {
  58. return fmt.Sprintf("go_l_ct_%d", lid)
  59. }
  60. func sourceItemKey(sid int64) string {
  61. return fmt.Sprintf("so_i_%d", sid)
  62. }
  63. func subjectProtocolKey(sid int64) string {
  64. return fmt.Sprintf("go_s_pt_%d", sid)
  65. }
  66. //go:generate $GOPATH/src/go-common/app/tool/cache/gen
  67. type _cache interface {
  68. // cache: -sync=true
  69. Like(c context.Context, id int64) (*likemdl.Item, error)
  70. // cache: -sync=true
  71. Likes(c context.Context, ids []int64) (map[int64]*likemdl.Item, error)
  72. // cache: -sync=true
  73. ActSubject(c context.Context, id int64) (*likemdl.SubjectItem, error)
  74. //cache: -sync=true -nullcache=-1 -check_null_code=$==-1
  75. LikeMissionBuff(ctx context.Context, sid int64, mid int64) (res int64, err error)
  76. //cache: -sync=true
  77. MissionGroupItems(ctx context.Context, lids []int64) (map[int64]*likemdl.MissionGroup, error)
  78. //cache: -sync=true -nullcache=-1 -check_null_code=$!=nil&&$==-1
  79. ActMission(ctx context.Context, sid int64, lid int64, mid int64) (res int64, err error)
  80. //cache:-sync=true
  81. ActLikeAchieves(ctx context.Context, sid int64) (res *likemdl.Achievements, err error)
  82. //cache:-sync=true
  83. ActMissionFriends(ctx context.Context, sid int64, lid int64) (res *likemdl.ActMissionGroups, err error)
  84. //cache:-sync=true
  85. ActUserAchieve(ctx context.Context, id int64) (res *likemdl.ActLikeUserAchievement, err error)
  86. // cache
  87. MatchSubjects(c context.Context, ids []int64) (map[int64]*likemdl.Object, error)
  88. // cache:-sync=true
  89. LikeContent(c context.Context, ids []int64) (map[int64]*likemdl.LikeContent, error)
  90. // cache
  91. SourceItemData(c context.Context, sid int64) ([]int64, error)
  92. // cache:-sync=true
  93. ActSubjectProtocol(c context.Context, sid int64) (res *likemdl.ActSubjectProtocol, err error)
  94. }
  95. //go:generate $GOPATH/src/go-common/app/tool/cache/mc
  96. type _mc interface {
  97. // mc: -key=likeKey
  98. CacheLike(c context.Context, id int64) (*likemdl.Item, error)
  99. // mc: -key=likeKey
  100. CacheLikes(c context.Context, id []int64) (map[int64]*likemdl.Item, error)
  101. // mc: -key=likeKey -expire=d.mcPerpetualExpire -encode=json
  102. AddCacheLikes(c context.Context, items map[int64]*likemdl.Item) error
  103. // mc: -key=likeKey -expire=d.mcPerpetualExpire -encode=json
  104. AddCacheLike(c context.Context, key int64, value *likemdl.Item) error
  105. // mc: -key=actSubjectKey
  106. CacheActSubject(c context.Context, id int64) (*likemdl.SubjectItem, error)
  107. // mc: -key=actSubjectKey -expire=d.mcPerpetualExpire -encode=pb
  108. AddCacheActSubject(c context.Context, key int64, value *likemdl.SubjectItem) error
  109. // mc: -key=actSubjectMaxIDKey
  110. CacheActSubjectMaxID(c context.Context) (res int64, err error)
  111. // mc: -key=actSubjectMaxIDKey -expire=d.mcPerpetualExpire -encode=raw
  112. AddCacheActSubjectMaxID(c context.Context, sid int64) error
  113. // mc: -key=likeMaxIDKey
  114. CacheLikeMaxID(c context.Context) (res int64, err error)
  115. // mc: -key=likeMaxIDKey -expire=d.mcPerpetualExpire -encode=raw
  116. AddCacheLikeMaxID(c context.Context, lid int64) error
  117. //mc: -key=likeMissionBuffKey
  118. CacheLikeMissionBuff(c context.Context, sid int64, mid int64) (res int64, err error)
  119. //mc: -key=likeMissionBuffKey
  120. AddCacheLikeMissionBuff(c context.Context, sid int64, val int64, mid int64) error
  121. //mc: -key=likeMissionGroupIDkey
  122. CacheMissionGroupItems(ctx context.Context, lids []int64) (map[int64]*likemdl.MissionGroup, error)
  123. //mc: -key=likeMissionGroupIDkey -expire=d.mcItemExpire -encode=pb
  124. AddCacheMissionGroupItems(ctx context.Context, val map[int64]*likemdl.MissionGroup) error
  125. //mc: -key=likeActMissionKey
  126. CacheActMission(c context.Context, sid int64, lid int64, mid int64) (res int64, err error)
  127. //mc: -key=likeActMissionKey -expire=d.mcPerpetualExpire -encode=raw
  128. AddCacheActMission(c context.Context, sid int64, val int64, lid int64, mid int64) error
  129. //mc: -key=actAchieveKey
  130. CacheActLikeAchieves(c context.Context, sid int64) (res *likemdl.Achievements, err error)
  131. //mc: -key=actAchieveKey -expire=d.mcItemExpire -encode=pb
  132. AddCacheActLikeAchieves(c context.Context, sid int64, res *likemdl.Achievements) error
  133. //mc: -key=actMissionFriendsKey
  134. CacheActMissionFriends(c context.Context, sid int64, lid int64) (res *likemdl.ActMissionGroups, err error)
  135. //mc: -key=actMissionFriendsKey
  136. DelCacheActMissionFriends(c context.Context, sid int64, lid int64) error
  137. //mc: -key=actMissionFriendsKey -expire=d.mcItemExpire -encode=pb
  138. AddCacheActMissionFriends(c context.Context, sid int64, res *likemdl.ActMissionGroups, lid int64) error
  139. //mc: -key=actUserAchieveKey
  140. CacheActUserAchieve(c context.Context, id int64) (res *likemdl.ActLikeUserAchievement, err error)
  141. //mc: -key=actUserAchieveKey -expire=d.mcItemExpire -encode=pb
  142. AddCacheActUserAchieve(c context.Context, id int64, val *likemdl.ActLikeUserAchievement) error
  143. //mc: -key=actUserAchieveAwardKey
  144. CacheActUserAward(c context.Context, id int64) (res int64, err error)
  145. //mc: -key=actUserAchieveAwardKey -expire=d.mcPerpetualExpire -encode=raw
  146. AddCacheActUserAward(c context.Context, id int64, val int64) error
  147. // mc: -key=subjectStatKey
  148. CacheSubjectStat(c context.Context, sid int64) (*likemdl.SubjectStat, error)
  149. // mc: -key=subjectStatKey -expire=d.mcSubStatExpire -encode=json
  150. AddCacheSubjectStat(c context.Context, sid int64, value *likemdl.SubjectStat) error
  151. // mc: -key=viewRankKey
  152. CacheViewRank(c context.Context, sid int64) (string, error)
  153. // mc: -key=viewRankKey -expire=d.mcViewRankExpire -encode=raw
  154. AddCacheViewRank(c context.Context, sid int64, value string) error
  155. // mc: -key=likeContentKey
  156. CacheLikeContent(c context.Context, lids []int64) (res map[int64]*likemdl.LikeContent, err error)
  157. // mc: -key=likeContentKey -expire=d.mcPerpetualExpire -encode=pb
  158. AddCacheLikeContent(c context.Context, val map[int64]*likemdl.LikeContent) error
  159. // mc: -key=sourceItemKey
  160. CacheSourceItemData(c context.Context, sid int64) ([]int64, error)
  161. // mc: -key=sourceItemKey -expire=d.mcSourceItemExpire -encode=json
  162. AddCacheSourceItemData(c context.Context, sid int64, lids []int64) error
  163. // mc: -key=subjectProtocolKey
  164. CacheActSubjectProtocol(c context.Context, sid int64) (res *likemdl.ActSubjectProtocol, err error)
  165. // mc: -key=subjectProtocolKey -expire=d.mcProtocolExpire -encode=pb
  166. AddCacheActSubjectProtocol(c context.Context, sid int64, value *likemdl.ActSubjectProtocol) error
  167. }