memcache.go 658 B

12345678910111213141516171819202122232425262728293031
  1. package dao
  2. import (
  3. "context"
  4. "strconv"
  5. "go-common/app/interface/main/app-player/model/archive"
  6. "go-common/library/cache/memcache"
  7. "github.com/pkg/errors"
  8. )
  9. const (
  10. _prefixArc = "p_"
  11. )
  12. func keyArc(aid int64) string {
  13. return _prefixArc + strconv.FormatInt(aid, 10)
  14. }
  15. // AddArchiveCache add archive cache.
  16. func (d *Dao) AddArchiveCache(c context.Context, aid int64, arc *archive.Info) (err error) {
  17. conn := d.mc.Get(c)
  18. key := keyArc(aid)
  19. item := &memcache.Item{Key: key, Object: arc, Flags: memcache.FlagProtobuf, Expiration: 0}
  20. if err = conn.Set(item); err != nil {
  21. err = errors.Wrapf(err, "conn.Set(%v)", item)
  22. }
  23. conn.Close()
  24. return
  25. }