From the documentation http://flask-kvsession.readthedocs.org/en/0.3.1/ atcleanup_sessions()
, it says this method should be called periodically to clean up expired sessions.
Does it mean that the session memory usage will expand during the lifetime of the application if I do not clean it up?
What are the bad implications if I do not clean them up periodically?
What would be some good ways to schedule the periodic cleanup within the application?
Can I use Redis as the storage backend and set an expiry automatically?
You can register a 'after_request' or 'before_request' to handle cleanup periodically.
If you use RedisStore, KVSession would pick the flask config item PERMANENT_SESSION_LIFETIME and do session cleanup automatically. Only for the Backends that don't support it TimeToLiveMixin interface you have to do it by manually.
You can use Redis, but it will still store expired sessions. The implications of storing expired sessions is that you'll waste disk space or RAM, which is especially bad with Redis.
As far as scheduling a cleanup, just create a daily script with cron or upstart that runs
cleanup_sessions
. Alternatively, you could also modifysimplekv
to set expiration times on keys: https://github.com/mbr/simplekv/blob/master/simplekv/memory/redisstore.py