pip install beaker
python
import beaker
python
from beaker.middleware import SessionMiddleware
session_opts = {
'session.type': 'file',
'session.cookie_expires': True,
'session.data_dir': './cache',
'session.auto': True
}
app = SessionMiddleware(app, session_opts)
python
session = environ['beaker.session']
session['username'] = 'example_user'
session.save()
python
session = environ['beaker.session']
username = session.get('username')
python
session = environ['beaker.session']
del session['username']
session.save()
python
session = environ['beaker.session']
session.delete()
python
from beaker.cache import CacheManager
cache_opts = {
'cache.type': 'file',
'cache.data_dir': './cache',
'cache.lock_dir': './cache/lock'
}
cache = CacheManager(**cache_opts).get_cache('my_cache')
cache.set('key', 'value')
python
cache = CacheManager(**cache_opts).get_cache('my_cache')
value = cache.get('key')
python
cache = CacheManager(**cache_opts).get_cache('my_cache')
cache.remove('key')