Home

About Beaker

Beaker is a caching library that includes Session and Cache objects built on Myghty's Container API used in MyghtyUtils. WSGI middleware is also included to manage Session objects and signed cookies.

Beaker caching is implemented with namespaces allowing one to store not only any Python data that can be pickled, but also multiple versions of it by using multiple keys for a single piece of data under a namespace.

Many thanks to Mike Bayer for his excellent work on Myghty and MyghtyUtils

Key features

  • Fast, robust performance
  • Multiple reader/single writer lock system to avoid duplicate simultaneous cache creation
  • Cache back-ends include dbm, file, memory, memcached, and database (Using SQLAlchemy for multiple-db vendor support)
  • Signed cookies to prevent session hijacking/spoofing
  • Cookie-only sessions to remove the need for a db or file backend (ideal for clustered systems)
  • Extensible Container object to support new back-ends
  • Caches can be divided into namespaces (to represent templates, objects, etc.) then keyed for different copies
  • Create functions for automatic call-backs to create new cache copies after expiration
  • Fine-grained toggling of back-ends, keys, and expiration per Cache object

Download

Beaker can be installed via setuptools:

1
$ sudo easy_install Beaker

Or from source with Mercurial:

1
hg clone http://bitbucket.org/bbangert/beaker/

View the Beaker repository

Documentation

Sample Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
from beaker.middleware import SessionMiddleware

def your_wsgi_app(environ, start_response):
    session = environ['beaker.session']
    if not session.has_key('value'):
        session['value'] = 0
    session['value'] += 1
    session.save()
    start_response('200 OK', [('Content-type', 'text/plain')])
    return ['The current value is: %d' % session['value']]

# Setup your WSGI app to be wrapped in
wsgiapp = your_wsgi_app
# Wrap our app with the session, use a signed cookie named 'mysession'
wsgiapp = SessionMiddleware(wsgiapp, key='mysession', secret='randomsecret')

Labels

wsgi wsgi Delete
beaker beaker Delete
cache cache Delete
session session Delete
middleware middleware Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Mar 06, 2008

    jonathan says:

    could someone update the "Sample Usage" section to reflect a pylons app, along w...

    could someone update the "Sample Usage" section to reflect a pylons app, along with the appropriate filenames?