Sessions: Clean up auth_session_cache.go #98 #782

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2022-10-03 23:46:20 +02:00
parent 05cdcbaf9d
commit b390e34b78

View file

@ -11,23 +11,10 @@ import (
"github.com/photoprism/photoprism/pkg/rnd" "github.com/photoprism/photoprism/pkg/rnd"
) )
// Create a new session cache with an expiration time of 15 minutes.
var sessionCacheExpiration = 15 * time.Minute var sessionCacheExpiration = 15 * time.Minute
var sessionCache = gc.New(sessionCacheExpiration, 5*time.Minute) var sessionCache = gc.New(sessionCacheExpiration, 5*time.Minute)
// FlushSessionCache resets the session cache.
func FlushSessionCache() {
sessionCache.Flush()
}
// DeleteFromSessionCache deletes a cached session.
func DeleteFromSessionCache(id string) {
if id == "" {
return
}
sessionCache.Delete(id)
}
// FindSession returns an existing session or nil if not found. // FindSession returns an existing session or nil if not found.
func FindSession(id string) (*Session, error) { func FindSession(id string) (*Session, error) {
found := &Session{} found := &Session{}
@ -61,3 +48,17 @@ func FindSession(id string) (*Session, error) {
return found, fmt.Errorf("expired") return found, fmt.Errorf("expired")
} }
// FlushSessionCache resets the session cache.
func FlushSessionCache() {
sessionCache.Flush()
}
// DeleteFromSessionCache deletes a session from the cache.
func DeleteFromSessionCache(id string) {
if id == "" {
return
}
sessionCache.Delete(id)
}