Cache object
The Cache object is used to manage a set of cache files and their associated backend. The backends can be rotated on the fly by specifying an alternate type when used.
Container and Namespace classes
dict() -> new empty dictionary. dict(mapping) -> new dictionary initialized from a mapping object’s
(key, value) pairs.
d = {} for k, v in seq:
d[k] = v
Handles dictionary operations and locking for a namespace of values.
The implementation for setting and retrieving the namespace data is handled by subclasses.
NamespaceManager may be used alone, or may be privately accessed by one or more Container objects. Container objects provide per-key services like expiration times and automatic recreation of values.
Multiple NamespaceManagers created with a particular name will all share access to the same underlying datasource and will attempt to synchronize against a common mutex object. The scope of this sharing may be within a single process or across multiple processes, depending on the type of NamespaceManager used.
The NamespaceManager itself is generally threadsafe, except in the case of the DBMNamespaceManager in conjunction with the gdbm dbm implementation.
Middleware
Session proxy/lazy creator
This object proxies access to the actual session object, so that in the case that the session hasn’t been used before, it will be setup. This avoid creating and loading the session from persistent storage unless its actually used during the request.
Synchronization functions.
File- and mutex-based mutual exclusion synchronizers are provided, as well as a name-based mutex which locks within an application based on a string name.
a proxy for an RLock object that is stored in a name based registry.
Multiple threads can get a reference to the same RLock based on the name alone, and synchronize operations related to that name.
a synchronizer which locks using flock().
Adapted for Python/multithreads from Apache::Session::Lock::File, http://search.cpan.org/src/CWEST/Apache-Session-1.81/Session/Lock/File.pm
This module does not unlink temporary files, because it interferes with proper locking. This can cause problems on certain systems (Linux) whose file systems (ext2) do not perform well with lots of files in one directory. To prevent this you should use a script to clean out old files from your lock directory.
Beaker utilities
An efficient/threadsafe singleton map algorithm, a.k.a. “get a value based on this key, and create if not found or not valid” paradigm:
exists && isvalid ? get : create
Works with weakref dictionaries and the LRUCache to handle items asynchronously disappearing from the dictionary.
Use python 2.3.3 or greater ! a major bug was just fixed in Nov. 2003 that was driving me nuts with garbage collection/weakrefs in this section.
Decode a Base64 encoded string.
s is the string to decode. Optional altchars must be a string of at least length 2 (additional characters are ignored) which specifies the alternative alphabet used instead of the ‘+’ and ‘/’ characters.
The decoded string is returned. A TypeError is raised if s were incorrectly padded or if there are non-alphabet characters present in the string.
Encode a string using Base64.
s is the string to encode. Optional altchars must be a string of at least length 2 (additional characters are ignored) which specifies an alternative alphabet for the ‘+’ and ‘/’ characters. This allows an application to e.g. generate url or filesystem safe Base64 strings.
The encoded string is returned.