util.go 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. package memcache
  2. import (
  3. "github.com/gogo/protobuf/proto"
  4. )
  5. // RawItem item with FlagRAW flag.
  6. //
  7. // Expiration is the cache expiration time, in seconds: either a relative
  8. // time from now (up to 1 month), or an absolute Unix epoch time.
  9. // Zero means the Item has no expiration time.
  10. func RawItem(key string, data []byte, flags uint32, expiration int32) *Item {
  11. return &Item{Key: key, Flags: flags | FlagRAW, Value: data, Expiration: expiration}
  12. }
  13. // JSONItem item with FlagJSON flag.
  14. //
  15. // Expiration is the cache expiration time, in seconds: either a relative
  16. // time from now (up to 1 month), or an absolute Unix epoch time.
  17. // Zero means the Item has no expiration time.
  18. func JSONItem(key string, v interface{}, flags uint32, expiration int32) *Item {
  19. return &Item{Key: key, Flags: flags | FlagJSON, Object: v, Expiration: expiration}
  20. }
  21. // ProtobufItem item with FlagProtobuf flag.
  22. //
  23. // Expiration is the cache expiration time, in seconds: either a relative
  24. // time from now (up to 1 month), or an absolute Unix epoch time.
  25. // Zero means the Item has no expiration time.
  26. func ProtobufItem(key string, message proto.Message, flags uint32, expiration int32) *Item {
  27. return &Item{Key: key, Flags: flags | FlagProtobuf, Object: message, Expiration: expiration}
  28. }