mc.go 859 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package block
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/library/cache/memcache"
  6. "github.com/pkg/errors"
  7. )
  8. func userKey(mid int64) (key string) {
  9. key = fmt.Sprintf("u_%d", mid)
  10. return
  11. }
  12. func userDetailKey(mid int64) (key string) {
  13. key = fmt.Sprintf("ud_%d", mid)
  14. return
  15. }
  16. // DeleteUserCache .
  17. func (d *Dao) DeleteUserCache(c context.Context, mid int64) (err error) {
  18. var (
  19. key = userKey(mid)
  20. conn = d.mc.Get(c)
  21. )
  22. defer conn.Close()
  23. if err = conn.Delete(key); err != nil {
  24. if err == memcache.ErrNotFound {
  25. err = nil
  26. return
  27. }
  28. err = errors.Wrapf(err, "key : %s", key)
  29. return
  30. }
  31. return
  32. }
  33. // DeleteUserDetailCache delete user detail cache
  34. func (d *Dao) DeleteUserDetailCache(c context.Context, mid int64) (err error) {
  35. var (
  36. key = userDetailKey(mid)
  37. conn = d.mc.Get(c)
  38. )
  39. defer conn.Close()
  40. err = conn.Delete(key)
  41. return
  42. }