BigBrotherBot v1.9.0
System Development Information for the BigBrotherBot project.

b3::lib::beaker::cache Namespace Reference

Classes

class  Cache
class  CacheManager

Functions

def cache_region
def region_invalidate

Variables

dictionary clsmap
dictionary cache_regions = {}
dictionary cache_managers = {}
tuple NamespaceManager = entry_point.load()
 name = entry_point.name
tuple tb = StringIO()

Detailed Description

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.

Advanced users can add new backends in b3.lib.beaker.backends


Function Documentation

def b3::lib::beaker::cache::cache_region (   region,
  deco_args 
)
Decorate a function to cache itself using a cache region

The region decorator requires arguments if there are more than
2 of the same named function, in the same module. This is
because the namespace used for the functions cache is based on
the functions name and the module.


Example::

    # Add cache region settings to beaker:
    b3.lib.beaker.cache.cache_regions.update(dict_of_config_region_options))

    @cache_region('short_term', 'some_data')
    def populate_things(search_term, limit, offset):
        return load_the_data(search_term, limit, offset)

    return load('rabbits', 20, 0)

.. note::

    The function being decorated must only be called with
    positional arguments.

def b3::lib::beaker::cache::region_invalidate (   namespace,
  region,
  args 
)
Invalidate a cache region namespace or decorated function

This function only invalidates cache spaces created with the
cache_region decorator.

:param namespace: Either the namespace of the result to invalidate, or the
    cached function reference

:param region: The region the function was cached to. If the function was
    cached to a single region then this argument can be None

:param args: Arguments that were used to differentiate the cached
    function as well as the arguments passed to the decorated
    function

Example::

    # Add cache region settings to beaker:
    b3.lib.beaker.cache.cache_regions.update(dict_of_config_region_options))

    def populate_things(invalidate=False):

        @cache_region('short_term', 'some_data')
        def load(search_term, limit, offset):
            return load_the_data(search_term, limit, offset)

        # If the results should be invalidated first
        if invalidate:
            region_invalidate(load, None, 'some_data',
                                    'rabbits', 20, 0)
        return load('rabbits', 20, 0)


Variable Documentation

Initial value:
00001 {
00002           'memory':container.MemoryNamespaceManager,
00003           'dbm':container.DBMNamespaceManager,
00004           'file':container.FileNamespaceManager,
00005           'ext:memcached':memcached.MemcachedNamespaceManager,
00006           'ext:database':database.DatabaseNamespaceManager,
00007           'ext:sqla': sqla.SqlaNamespaceManager,
00008           'ext:google': google.GoogleNamespaceManager,
00009           }
b3::lib::beaker::cache::name = entry_point.name
tuple b3::lib::beaker::cache::NamespaceManager = entry_point.load()
tuple b3::lib::beaker::cache::tb = StringIO()
 All Classes Namespaces Files Functions Variables Properties