localcache.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package dao
  2. import (
  3. "time"
  4. "go-common/app/service/main/ugcpay-rank/internal/conf"
  5. "go-common/app/service/main/ugcpay-rank/internal/model"
  6. "github.com/bluele/gcache"
  7. "github.com/pkg/errors"
  8. )
  9. // LCStoreElecUPRank .
  10. func (d *Dao) LCStoreElecUPRank(upMID, ver int64, rank *model.RankElecUPProto) (err error) {
  11. key := elecUPRankKey(upMID, ver)
  12. if err = d.elecUPRankLC.SetWithExpire(key, rank, time.Duration(conf.Conf.LocalCache.ElecUPRankTTL)); err != nil {
  13. err = errors.WithStack(err)
  14. return
  15. }
  16. return
  17. }
  18. // LCStoreElecAVRank .
  19. func (d *Dao) LCStoreElecAVRank(avID, ver int64, rank *model.RankElecAVProto) (err error) {
  20. key := elecAVRankKey(avID, ver)
  21. if err = d.elecAVRankLC.SetWithExpire(key, rank, time.Duration(conf.Conf.LocalCache.ElecAVRankTTL)); err != nil {
  22. err = errors.WithStack(err)
  23. return
  24. }
  25. return
  26. }
  27. // LCLoadElecUPRank .
  28. func (d *Dao) LCLoadElecUPRank(upMID, ver int64) (rank *model.RankElecUPProto, err error) {
  29. key := elecUPRankKey(upMID, ver)
  30. item, err := d.elecUPRankLC.Get(key)
  31. if err != nil {
  32. if err == gcache.KeyNotFoundError {
  33. err = nil
  34. rank = nil
  35. return
  36. }
  37. err = errors.WithStack(err)
  38. return
  39. }
  40. rank = item.(*model.RankElecUPProto)
  41. return
  42. }
  43. // LCLoadElecAVRank .
  44. func (d *Dao) LCLoadElecAVRank(avID, ver int64) (rank *model.RankElecAVProto, err error) {
  45. key := elecAVRankKey(avID, ver)
  46. item, err := d.elecAVRankLC.Get(key)
  47. if err != nil {
  48. if err == gcache.KeyNotFoundError {
  49. err = nil
  50. rank = nil
  51. return
  52. }
  53. err = errors.WithStack(err)
  54. return
  55. }
  56. rank = item.(*model.RankElecAVProto)
  57. return
  58. }