Products.BeakerZopeSessionManager is a replacement for the default Zope 4 session implementation. It uses Beaker as a backend (via collective.beaker) and adapts the Beaker session to provide the same interface as a normal Zope session.
Beaker is a better alternative to the default session implementation for several reasons:
- The Zope session implementation does not perform well in high-write scenarios.
- Beaker provides better flexibility in where session data is actually stored.
- Beaker is used and maintained outside of the Zope ecosystem.
If you are developing a product that needs sessions but are not already using Zope sessions, you should probably just use collective.beaker directly. This product is meant for use with existing add-ons that already use Zope sessions (i.e. request.SESSION).
Using PIP:
pip install Products.BeakerZopeSessionManager
Include the line <include package="collective.beaker" />
in yout site.zcml
Edit the file lib/python3.7/site-packages/Zope2/Startup/serve.py
inside your virtual env.
Replace (line 203):
try:
server(app)
except (SystemExit, KeyboardInterrupt) as e:
with:
try:
from beaker.middleware import SessionMiddleware
config = {
'session.type': 'file',
'session.auto': True,
'session.save_accessed_time': True,
'session.data_dir': '/tmp/sessions/data',
'session.lock_dir': '/tmp/sessions/lock',
'session.timeout': 28800
}
server(SessionMiddleware(app, config))
except (SystemExit, KeyboardInterrupt) as e:
For more info on how to configure your Beaker, please refer to Beaker documentation.
- Beaker does not automatically clean up old sessions, so you may want to set up a cron job to take care of this.
- Gabriel Gisoldo [gabrielgisoldo]