archive.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package archive
  2. import (
  3. "context"
  4. "strconv"
  5. arccli "go-common/app/service/main/archive/api"
  6. "go-common/library/cache/memcache"
  7. "github.com/pkg/errors"
  8. )
  9. const (
  10. _prefixArc = "a3p_"
  11. _prefixView = "avp_"
  12. )
  13. func keyArc(aid int64) string {
  14. return _prefixArc + strconv.FormatInt(aid, 10)
  15. }
  16. func keyView(aid int64) string {
  17. return _prefixView + strconv.FormatInt(aid, 10)
  18. }
  19. // UpArcCache update archive cache
  20. func (d *Dao) UpArcCache(c context.Context, a *arccli.Arc) (err error) {
  21. conn := d.mc.Get(c)
  22. item := &memcache.Item{Key: keyArc(a.Aid), Object: a, Flags: memcache.FlagJSON, Expiration: 0}
  23. if err = conn.Set(item); err != nil {
  24. err = errors.Wrapf(err, "conn.Set(%v)", item)
  25. }
  26. conn.Close()
  27. return
  28. }
  29. // UpViewCache up all app cache .
  30. func (d *Dao) UpViewCache(c context.Context, v *arccli.ViewReply) (err error) {
  31. conn := d.mc.Get(c)
  32. item := &memcache.Item{Key: keyView(v.Arc.Aid), Object: v, Flags: memcache.FlagJSON, Expiration: 0}
  33. if err = conn.Set(item); err != nil {
  34. err = errors.Wrapf(err, "conn.Set(%v)", item)
  35. }
  36. conn.Close()
  37. return
  38. }