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

b3::lib::beaker::cache::CacheManager Class Reference

List of all members.

Public Member Functions

def __init__
def get_cache
def get_cache_region
def region
def region_invalidate
def cache
def invalidate

Public Attributes

 kwargs
 regions

Constructor & Destructor Documentation

def b3::lib::beaker::cache::CacheManager::__init__ (   self,
  kwargs 
)
Initialize a CacheManager object with a set of options

Options should be parsed with the
:func:`~beaker.util.parse_cache_config_options` function to
ensure only valid options are used.


Member Function Documentation

def b3::lib::beaker::cache::CacheManager::cache (   self,
  args,
  kwargs 
)
Decorate a function to cache itself with supplied parameters

:param args: Used to make the key unique for this function, as in region()
    above.

:param kwargs: Parameters to be passed to get_cache(), will override defaults

Example::

    # Assuming a cache object is available like:
    cache = CacheManager(dict_of_config_options)
    
    
    def populate_things():

@cache.cache('mycache', expire=15)
def load(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::CacheManager::get_cache (   self,
  name,
  kwargs 
)
def b3::lib::beaker::cache::CacheManager::get_cache_region (   self,
  name,
  region 
)
def b3::lib::beaker::cache::CacheManager::invalidate (   self,
  func,
  args,
  kwargs 
)
Invalidate a cache decorated function

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

:param func: Decorated function to invalidate

:param args: Used to make the key unique for this function, as in region()
    above.

:param kwargs: Parameters that were passed for use by get_cache(), note that
    this is only required if a ``type`` was specified for the
    function

Example::
    
    # Assuming a cache object is available like:
    cache = CacheManager(dict_of_config_options)
    
    
    def populate_things(invalidate=False):

@cache.cache('mycache', type="file", expire=15)
def load(search_term, limit, offset):
    return load_the_data(search_term, limit, offset)

# If the results should be invalidated first
if invalidate:
    cache.invalidate(load, 'mycache', 'rabbits', 20, 0, type="file")
return load('rabbits', 20, 0)

def b3::lib::beaker::cache::CacheManager::region (   self,
  region,
  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::
    
    # Assuming a cache object is available like:
    cache = CacheManager(dict_of_config_options)
    
    
    def populate_things():

@cache.region('short_term', 'some_data')
def load(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::CacheManager::region_invalidate (   self,
  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
   name of the cached function

: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::
    
    # Assuming a cache object is available like:
    cache = CacheManager(dict_of_config_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:
    cache.region_invalidate(load, None, 'some_data',
                            'rabbits', 20, 0)
return load('rabbits', 20, 0)
    


Member Data Documentation


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Properties