cache.go 683 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package cache
  2. import (
  3. cache "github.com/patrickmn/go-cache"
  4. "time"
  5. )
  6. var (
  7. std *cache.Cache
  8. )
  9. func init() {
  10. std = cache.New(time.Minute*10, time.Minute*30)
  11. }
  12. func Set(name string, value interface{}) {
  13. std.Set(name, value, 0)
  14. }
  15. func Get(name string) (interface{}, bool) {
  16. return std.Get(name)
  17. }
  18. func SetEx(name string, value interface{}, expired time.Duration) {
  19. std.Set(name, value, expired)
  20. }
  21. func Delete(name string) {
  22. std.Delete(name)
  23. }
  24. func Count() int {
  25. return std.ItemCount()
  26. }
  27. func Flush() {
  28. std.Flush()
  29. }
  30. func Save(filename string) (err error) {
  31. return std.SaveFile(filename)
  32. }
  33. func Load(filename string) (err error) {
  34. return std.LoadFile(filename)
  35. }