dao.cache.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. // 用户点赞列表
  7. // cache: -singleflight=true -ignores=||start,end
  8. userLikeList(c context.Context, mid int64, businessID int64, state int8, start, end int) (res []*model.ItemLikeRecord, err error)
  9. }
  10. */
  11. package dao
  12. import (
  13. "context"
  14. "go-common/app/service/main/thumbup/model"
  15. "go-common/library/stat/prom"
  16. "golang.org/x/sync/singleflight"
  17. )
  18. var _ _cache
  19. var cacheSingleFlights = [1]*singleflight.Group{{}}
  20. // userLikeList 用户点赞列表
  21. func (d *Dao) userLikeList(c context.Context, id int64, businessID int64, state int8, start, end int) (res []*model.ItemLikeRecord, err error) {
  22. addCache := true
  23. res, err = d.CacheUserLikeList(c, id, businessID, state, start, end)
  24. if err != nil {
  25. addCache = false
  26. err = nil
  27. }
  28. if len(res) != 0 {
  29. prom.CacheHit.Incr("userLikeList")
  30. return
  31. }
  32. var rr interface{}
  33. sf := d.cacheSFuserLikeList(id, businessID, state, start, end)
  34. rr, err, _ = cacheSingleFlights[0].Do(sf, func() (r interface{}, e error) {
  35. prom.CacheMiss.Incr("userLikeList")
  36. r, e = d.RawUserLikeList(c, id, businessID, state, start, end)
  37. return
  38. })
  39. res = rr.([]*model.ItemLikeRecord)
  40. if err != nil {
  41. return
  42. }
  43. miss := res
  44. if !addCache {
  45. return
  46. }
  47. d.cache.Do(c, func(c context.Context) {
  48. d.AddCacheUserLikeList(c, id, miss, businessID, state)
  49. })
  50. return
  51. }