beaker.container – Container and Namespace classes

Container and Namespace classes

Module Contents

class beaker.container.DBMNamespaceManager(namespace, dbmmodule=None, data_dir=None, dbm_dir=None, lock_dir=None, digest_filenames=True, **kwargs)

Bases: beaker.container.OpenResourceNamespaceManager

NamespaceManager that uses dbm files for storage.

class beaker.container.FileNamespaceManager(namespace, data_dir=None, file_dir=None, lock_dir=None, digest_filenames=True, **kwargs)

Bases: beaker.container.OpenResourceNamespaceManager

NamespaceManager that uses binary files for storage.

Each namespace is implemented as a single file storing a dictionary of key/value pairs, serialized using the Python pickle module.

class beaker.container.MemoryNamespaceManager(namespace, **kwargs)

Bases: beaker.container.AbstractDictionaryNSManager

NamespaceManager that uses a Python dictionary for storage.

class beaker.container.NamespaceManager(namespace)

Handles dictionary operations and locking for a namespace of values.

NamespaceManager provides a dictionary-like interface, implementing __getitem__(), __setitem__(), and __contains__(), as well as functions related to lock acquisition.

The implementation for setting and retrieving the namespace data is handled by subclasses.

NamespaceManager may be used alone, or may be accessed by one or more Value objects. Value 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.

acquire_read_lock()

Establish a read lock.

This operation is called before a key is read. By default the function does nothing.

acquire_write_lock(wait=True, replace=False)

Establish a write lock.

This operation is called before a key is written. A return value of True indicates the lock has been acquired.

By default the function returns True unconditionally.

‘replace’ is a hint indicating the full contents of the namespace may be safely discarded. Some backends may implement this (i.e. file backend won’t unpickle the current contents).

do_remove()

Implement removal of the entire contents of this NamespaceManager.

e.g. for a file-based namespace, this would remove all the files.

The front-end to this method is the NamespaceManager.remove() method.

get_creation_lock(key)

Return a locking object that is used to synchronize multiple threads or processes which wish to generate a new cache value.

This function is typically an instance of FileSynchronizer, ConditionSynchronizer, or null_synchronizer.

The creation lock is only used when a requested value does not exist, or has been expired, and is only used by the Value key-management object in conjunction with a “createfunc” value-creation function.

has_key(key)

Return True if the given key is present in this Namespace.

keys()

Return the list of all keys.

This method may not be supported by all NamespaceManager implementations.

release_read_lock()

Release a read lock.

This operation is called after a key is read. By default the function does nothing.

release_write_lock()

Release a write lock.

This operation is called after a new value is written. By default this function does nothing.

remove()

Remove the entire contents of this NamespaceManager.

e.g. for a file-based namespace, this would remove all the files.

set_value(key, value, expiretime=None)

Sets a value in this NamespaceManager.

This is the same as __setitem__(), but also allows an expiration time to be passed at the same time.

class beaker.container.OpenResourceNamespaceManager(namespace)

Bases: beaker.container.NamespaceManager

A NamespaceManager where read/write operations require opening/ closing of a resource which is possibly mutexed.

class beaker.container.Value(key, namespace, createfunc=None, expiretime=None, starttime=None)

Implements synchronization, expiration, and value-creation logic for a single value stored in a NamespaceManager.

can_have_value()
clear_value()
createfunc
expire_argument
expiretime
get_value()
has_current_value()
has_value()

return true if the container has a value stored.

This is regardless of it being expired or not.

key
namespace
set_value(value, storedtime=None)
starttime
storedtime

Deprecated Classes

class beaker.container.Container

Implements synchronization and value-creation logic for a ‘value’ stored in a NamespaceManager.

Container and its subclasses are deprecated. The Value class is now used for this purpose.

class beaker.container.ContainerMeta(classname, bases, dict_)

Bases: type

class beaker.container.DBMContainer

Bases: beaker.container.Container

class beaker.container.FileContainer

Bases: beaker.container.Container

class beaker.container.MemoryContainer

Bases: beaker.container.Container