cache.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package dao
  2. import (
  3. "context"
  4. "strconv"
  5. "go-common/app/interface/openplatform/article/model"
  6. )
  7. func (d *Dao) cacheSFList(id int64) string {
  8. return strconv.FormatInt(id, 10)
  9. }
  10. func (d *Dao) cacheSFListArts(id int64) string {
  11. return strconv.FormatInt(id, 10)
  12. }
  13. func (d *Dao) cacheSFUpLists(id int64) string {
  14. return strconv.FormatInt(id, 10)
  15. }
  16. //go:generate $GOPATH/src/go-common/app/tool/cache/gen
  17. type _cache interface {
  18. // cache: -nullcache=&model.List{ID:-1} -check_null_code=$!=nil&&$.ID==-1 -singleflight=true
  19. List(c context.Context, id int64) (*model.List, error)
  20. // cache: -batch=100 -max_group=10 -nullcache=&model.List{ID:-1} -check_null_code=$!=nil&&$.ID==-1
  21. Lists(c context.Context, keys []int64) (map[int64]*model.List, error)
  22. // cache: -singleflight=true -nullcache=[]*model.ListArtMeta{{ID:-1}} -check_null_code=len($)==1&&$[0].ID==-1
  23. ListArts(c context.Context, id int64) ([]*model.ListArtMeta, error)
  24. // cache: -nullcache=[]*model.ListArtMeta{{ID:-1}} -check_null_code=len($)==1&&$[0].ID==-1
  25. ListsArts(c context.Context, ids []int64) (map[int64][]*model.ListArtMeta, error)
  26. // cache: -nullcache=-1 -batch=100 -max_group=10
  27. ArtsListID(c context.Context, keys []int64) (map[int64]int64, error)
  28. // cache: -nullcache=[]int64{-1} -check_null_code=len($)==1&&$[0]==-1 -singleflight=true
  29. UpLists(c context.Context, mid int64) ([]int64, error)
  30. // cache: -nullcache=&model.AuthorLimit{Limit:-1} -check_null_code=$!=nil&&$.Limit==-1
  31. Author(c context.Context, mid int64) (*model.AuthorLimit, error)
  32. }
  33. //go:generate $GOPATH/src/go-common/app/tool/cache/mc
  34. type _mc interface {
  35. // 获取文集文章列表缓存
  36. //mc: -key=listArtsKey
  37. CacheListArts(c context.Context, id int64) (res []*model.ListArtMeta, err error)
  38. // 增加文集含有的文章列表缓存
  39. //mc: -key=listArtsKey -expire=d.mcListArtsExpire
  40. AddCacheListArts(c context.Context, id int64, arts []*model.ListArtMeta) (err error)
  41. // 获取文章所属文集
  42. //mc: -key=articleListKey -type=get
  43. ArticleListCache(c context.Context, id int64) (res int64, err error)
  44. // 增加文章所属文集缓存
  45. //mc: -key=articleListKey -expire=d.mcArtListExpire
  46. SetArticlesListCache(c context.Context, arts map[int64]int64) (err error)
  47. //mc: -key=listKey
  48. CacheList(c context.Context, id int64) (res *model.List, err error)
  49. //mc: -key=listKey -expire=d.mcListExpire
  50. AddCacheList(c context.Context, id int64, list *model.List) (err error)
  51. //mc: -key=listKey
  52. CacheLists(c context.Context, ids []int64) (res map[int64]*model.List, err error)
  53. //mc: -key=listKey -expire=d.mcListExpire
  54. AddCacheLists(c context.Context, lists map[int64]*model.List) (err error)
  55. //mc: -key=listArtsKey
  56. CacheListsArts(c context.Context, ids []int64) (res map[int64][]*model.ListArtMeta, err error)
  57. //mc: -key=listArtsKey -expire=d.mcListArtsExpire
  58. AddCacheListsArts(c context.Context, arts map[int64][]*model.ListArtMeta) (err error)
  59. //mc: -key=articleListKey
  60. CacheArtsListID(c context.Context, ids []int64) (res map[int64]int64, err error)
  61. //mc: -key=articleListKey -expire=d.mcArtListExpire
  62. AddCacheArtsListID(c context.Context, arts map[int64]int64) (err error)
  63. //mc: -key=upListsKey -expire=d.mcUpListsExpire
  64. AddCacheUpLists(c context.Context, mid int64, lists []int64) (err error)
  65. //mc: -key=upListsKey
  66. CacheUpLists(c context.Context, id int64) (res []int64, err error)
  67. //mc: -key=listReadCountKey -expire=d.mcListReadExpire
  68. AddCacheListReadCount(c context.Context, id int64, read int64) (err error)
  69. //mc: -key=listReadCountKey
  70. CacheListReadCount(c context.Context, id int64) (res int64, err error)
  71. //mc: -key=listReadCountKey
  72. CacheListsReadCount(c context.Context, ids []int64) (res map[int64]int64, err error)
  73. //mc: -key=hotspotsKey -expire=d.mcHotspotExpire
  74. AddCacheHotspots(c context.Context, hots []*model.Hotspot) (err error)
  75. //mc: -key=hotspotsKey
  76. DelCacheHotspots(c context.Context) (err error)
  77. //mc: -key=hotspotsKey
  78. cacheHotspots(c context.Context) (res []*model.Hotspot, err error)
  79. //mc: -key=mcHotspotKey
  80. CacheHotspot(c context.Context, id int64) (res *model.Hotspot, err error)
  81. //mc: -key=mcHotspotKey -expire=d.mcHotspotExpire
  82. AddCacheHotspot(c context.Context, id int64, val *model.Hotspot) (err error)
  83. // 增加作者状态缓存
  84. //mc: -key=mcAuthorKey -expire=d.mcAuthorExpire
  85. AddCacheAuthor(c context.Context, mid int64, author *model.AuthorLimit) (err error)
  86. //mc: -key=mcAuthorKey
  87. CacheAuthor(c context.Context, mid int64) (res *model.AuthorLimit, err error)
  88. //mc: -key=mcAuthorKey
  89. DelCacheAuthor(c context.Context, mid int64) (err error)
  90. //mc: -key=slideArticlesKey
  91. CacheListArtsId(c context.Context, buvid string) (*model.ArticleViewList, error)
  92. //mc: -key=slideArticlesKey -expire=d.mcArticlesIDExpire
  93. AddCacheListArtsId(c context.Context, buvid string, val *model.ArticleViewList) error
  94. //mc: -key=slideArticlesKey
  95. DelCacheListArtsId(c context.Context, buvid string) error
  96. //mc: -key=AnniversaryKey -expire=60*60*24*30
  97. CacheAnniversary(c context.Context, mid int64) (*model.AnniversaryInfo, error)
  98. //mc: -key=mcTagKey
  99. CacheAidsByTag(c context.Context, tag int64) (*model.TagArts, error)
  100. //mc: -key=mcTagKey -expire=d.mcArticleTagExpire
  101. AddCacheAidsByTag(c context.Context, tag int64, val *model.TagArts) error
  102. //mc: -key=mcUpStatKey -expire=d.mcUpStatDailyExpire
  103. CacheUpStatDaily(c context.Context, mid int64) (*model.UpStat, error)
  104. //mc: -key=mcUpStatKey -expire=d.mcUpStatDailyExpire
  105. AddCacheUpStatDaily(c context.Context, mid int64, val *model.UpStat) error
  106. }
  107. // RebuildUpListsCache .
  108. func (d *Dao) RebuildUpListsCache(c context.Context, mid int64) (err error) {
  109. lists, err := d.RawUpLists(c, mid)
  110. if err != nil {
  111. return
  112. }
  113. return d.AddCacheUpLists(c, mid, lists)
  114. }
  115. // RebuildListReadCountCache .
  116. func (d *Dao) RebuildListReadCountCache(c context.Context, id int64) (err error) {
  117. res, err := d.RawListReadCount(c, id)
  118. if err != nil {
  119. return
  120. }
  121. return d.AddCacheListReadCount(c, id, res)
  122. }