From 0de755f138fa6c3711ff1f134b99da88cfb2a13a Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 18 Mar 2018 21:23:48 -0700 Subject: [PATCH] Let the SessionManager use a cacheclass instead of plain dict. --- frontends/etiquette_flask/etiquette_flask/common.py | 2 +- frontends/etiquette_flask/etiquette_flask/sessions.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/frontends/etiquette_flask/etiquette_flask/common.py b/frontends/etiquette_flask/etiquette_flask/common.py index 7b98090..d4eff7c 100644 --- a/frontends/etiquette_flask/etiquette_flask/common.py +++ b/frontends/etiquette_flask/etiquette_flask/common.py @@ -33,7 +33,7 @@ site.debug = True P = etiquette.photodb.PhotoDB() -session_manager = sessions.SessionManager() +session_manager = sessions.SessionManager(maxlen=10000) def P_wrapper(function): diff --git a/frontends/etiquette_flask/etiquette_flask/sessions.py b/frontends/etiquette_flask/etiquette_flask/sessions.py index fdfb892..5db9f5e 100644 --- a/frontends/etiquette_flask/etiquette_flask/sessions.py +++ b/frontends/etiquette_flask/etiquette_flask/sessions.py @@ -6,6 +6,8 @@ import werkzeug.wrappers import etiquette +from voussoirkit import cacheclass + SESSION_MAX_AGE = 86400 REQUEST_TYPES = (flask.Request, werkzeug.wrappers.Request, werkzeug.local.LocalProxy) @@ -30,8 +32,8 @@ def _normalize_token(token): class SessionManager: - def __init__(self): - self.sessions = {} + def __init__(self, maxlen=None): + self.sessions = cacheclass.Cache(maxlen=maxlen) def add(self, session): self.sessions[session.token] = session