case_mc.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. gmc "go-common/library/cache/memcache"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _prefixCaseInfo = "ca_in_%d"
  10. _prefixVoteCaseInfo = "vc_in_%d_%d"
  11. )
  12. func caseInfoKey(cid int64) string {
  13. return fmt.Sprintf(_prefixCaseInfo, cid)
  14. }
  15. func voteCaseInfoKey(mid int64, cid int64) string {
  16. return fmt.Sprintf(_prefixVoteCaseInfo, mid, cid)
  17. }
  18. // DelCaseInfoCache del case info cache info.
  19. func (d *Dao) DelCaseInfoCache(c context.Context, cid int64) (err error) {
  20. conn := d.mc.Get(c)
  21. defer conn.Close()
  22. if err = conn.Delete(caseInfoKey(cid)); err != nil {
  23. if err == gmc.ErrNotFound {
  24. err = nil
  25. return
  26. }
  27. log.Error("conn.Delete(%d) error(%v)", cid, err)
  28. }
  29. return
  30. }
  31. // DelVoteCaseCache del vote case cache info.
  32. func (d *Dao) DelVoteCaseCache(c context.Context, mid, cid int64) (err error) {
  33. conn := d.mc.Get(c)
  34. defer conn.Close()
  35. if err = conn.Delete(voteCaseInfoKey(mid, cid)); err != nil {
  36. if err == gmc.ErrNotFound {
  37. err = nil
  38. return
  39. }
  40. log.Error("conn.Delete(%d,%d) error(%v)", mid, cid, err)
  41. }
  42. return
  43. }