begin handling cleanup of session tokens

This commit is contained in:
Gregory Wells
2026-06-08 18:37:42 -04:00
parent 2a97ec72be
commit d162c32a57
2 changed files with 41 additions and 19 deletions
+18 -18
View File
@@ -7,14 +7,14 @@ import (
)
type MemoryStore[Value any] struct {
sessions map[string]Value
lock sync.RWMutex
Sessions map[string]Value
Lock sync.RWMutex
}
func NewMemoryStore[Value any]() *MemoryStore[Value] {
logging.Debug("Creating new in memory session store")
store := &MemoryStore[Value]{
sessions: make(map[string]Value),
Sessions: make(map[string]Value),
}
return store
}
@@ -22,24 +22,24 @@ func NewMemoryStore[Value any]() *MemoryStore[Value] {
func (m *MemoryStore[Value]) Create(key string, session Value) (err error) {
hashedkey := HashKey(key)
m.lock.Lock()
defer m.lock.Unlock()
_, exist := m.sessions[hashedkey]
m.Lock.Lock()
defer m.Lock.Unlock()
_, exist := m.Sessions[hashedkey]
if exist {
return ErrKeyAlreadyExists
}
m.sessions[hashedkey] = session
m.Sessions[hashedkey] = session
return nil
}
func (m *MemoryStore[Value]) Get(key string) (Value, error) {
var data Value
m.lock.RLock()
m.Lock.RLock()
hashedkey := HashKey(key)
data, exists := m.sessions[hashedkey]
m.lock.RUnlock()
data, exists := m.Sessions[hashedkey]
m.Lock.RUnlock()
if exists == false {
return data, ErrKeyNotFound
}
@@ -49,25 +49,25 @@ func (m *MemoryStore[Value]) Get(key string) (Value, error) {
func (m *MemoryStore[Value]) Update(sessionID string, session Value) error {
hashedkey := HashKey(sessionID)
m.lock.Lock()
defer m.lock.Unlock()
_, exist := m.sessions[hashedkey]
m.Lock.Lock()
defer m.Lock.Unlock()
_, exist := m.Sessions[hashedkey]
if !exist {
return ErrKeyNotFound
}
m.sessions[hashedkey] = session
m.Sessions[hashedkey] = session
return nil
}
func (m *MemoryStore[Value]) Delete(sessionID string) error {
hashedkey := HashKey(sessionID)
m.lock.Lock()
defer m.lock.Unlock()
_, exist := m.sessions[hashedkey]
m.Lock.Lock()
defer m.Lock.Unlock()
_, exist := m.Sessions[hashedkey]
if !exist {
return ErrKeyNotFound
}
delete(m.sessions, hashedkey)
delete(m.Sessions, hashedkey)
return nil
}