photoprism/internal/session/store.go
Michael Mayer bdf0cde8a6 Backend: Add session package #169
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2019-12-28 09:48:36 +01:00

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
}