cache.go 617 B

1234567891011121314151617181920212223242526272829303132
  1. package cache
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/patrickmn/go-cache"
  6. )
  7. type Cache struct {
  8. C *cache.Cache
  9. }
  10. func (c *Cache) getCache(myId string) (interface{}, bool) {
  11. return c.C.Get(myId)
  12. }
  13. func (c *Cache) setCache(myId string, myVal interface{}) {
  14. c.C.Set(myId, myVal, 3*time.Hour)
  15. }
  16. func (c *Cache) setCacheTimeout(myId string, myVal interface{}, timeout int64) {
  17. c.C.Set(myId, myVal, time.Duration(timeout)*time.Second)
  18. }
  19. func (c *Cache) setToken(userId int, token string) {
  20. c.C.Set(fmt.Sprintf("token_%d", userId), token, 3*time.Hour)
  21. }
  22. func (c *Cache) delCache(myId string) {
  23. c.C.Delete(myId)
  24. }