memcache.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "strconv"
  6. gmc "go-common/library/cache/memcache"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _opinion = "op_v2_" // user opinion prefix.
  11. _labourIsAnswer = "labour_%d" // key of labourIsAnswer
  12. _juryInfo = "jy_" // key of jury info
  13. _caseVoteTop = "ca_vo_top_%d"
  14. )
  15. // user opinion key.
  16. func opinionKey(opid int64) string {
  17. return _opinion + strconv.FormatInt(opid, 10)
  18. }
  19. // labourKey.
  20. func labourKey(mid int64) string {
  21. return fmt.Sprintf(_labourIsAnswer, mid)
  22. }
  23. // user jury info key.
  24. func juryInfoKey(mid int64) string {
  25. return _juryInfo + strconv.FormatInt(mid, 10)
  26. }
  27. func caseVoteTopKey(mid int64) string {
  28. return fmt.Sprintf(_caseVoteTop, mid)
  29. }
  30. // DelOpinionCache del opinion cache info.
  31. func (d *Dao) DelOpinionCache(c context.Context, vid int64) (err error) {
  32. conn := d.mc.Get(c)
  33. defer conn.Close()
  34. if err = conn.Delete(opinionKey(vid)); err != nil {
  35. if err == gmc.ErrNotFound {
  36. err = nil
  37. return
  38. }
  39. log.Error("conn.Delete(%d) error(%v)", vid, err)
  40. }
  41. return
  42. }
  43. // DelAnswerStateCache del answer state cache info.
  44. func (d *Dao) DelAnswerStateCache(c context.Context, mid int64) (err error) {
  45. conn := d.mc.Get(c)
  46. defer conn.Close()
  47. if err = conn.Delete(labourKey(mid)); err != nil {
  48. if err == gmc.ErrNotFound {
  49. err = nil
  50. return
  51. }
  52. log.Error("conn.Delete(%d) error(%v)", mid, err)
  53. }
  54. return
  55. }
  56. // DelJuryInfoCache del jury cache info.
  57. func (d *Dao) DelJuryInfoCache(c context.Context, mid int64) (err error) {
  58. conn := d.mc.Get(c)
  59. defer conn.Close()
  60. if err = conn.Delete(juryInfoKey(mid)); err != nil {
  61. if err == gmc.ErrNotFound {
  62. err = nil
  63. return
  64. }
  65. log.Error("conn.Delete(%d) error(%v)", mid, err)
  66. }
  67. return
  68. }
  69. // DelCaseVoteTopCache del case vote total cache.
  70. func (d *Dao) DelCaseVoteTopCache(c context.Context, mid int64) (err error) {
  71. conn := d.mc.Get(c)
  72. defer conn.Close()
  73. if err = conn.Delete(caseVoteTopKey(mid)); err != nil {
  74. if err == gmc.ErrNotFound {
  75. err = nil
  76. return
  77. }
  78. log.Error("conn.Delete(%d) error(%v)", mid, err)
  79. }
  80. return
  81. }