bdf0cde8a6
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
31 lines
525 B
Go
31 lines
525 B
Go
package session
|
|
|
|
import (
|
|
"time"
|
|
|
|
gc "github.com/patrickmn/go-cache"
|
|
)
|
|
|
|
var cache = gc.New(72*time.Hour, 30*time.Minute)
|
|
|
|
func Create(data interface{}) string {
|
|
token := Token()
|
|
cache.Set(token, data, gc.DefaultExpiration)
|
|
log.Debugf("session: created")
|
|
return token
|
|
}
|
|
|
|
func Delete(token string) {
|
|
cache.Delete(token)
|
|
log.Debugf("session: deleted")
|
|
}
|
|
|
|
func Get(token string) (data interface{}, exists bool) {
|
|
return cache.Get(token)
|
|
}
|
|
|
|
func Exists(token string) bool {
|
|
_, found := cache.Get(token)
|
|
|
|
return found
|
|
}
|