def cache_region(region, *deco_args):
 cache = [None]
 def decorate(func):
  namespace = util.func_namespace(func)
  def cached(*args):
   reg = cache_regions[region]
   if (not reg.get('enabled', True)):
    return func(*args)
   if (not cache[0]):
    if (region not in cache_regions):
     raise BeakerException(('Cache region not configured: %s' % region))
    cache[0] = Cache._get_cache(namespace, reg)
   cache_key = ' '.join(map(str, (deco_args + args)))
   def go():
    return func(*args)
   return cache[0].get_value(cache_key, createfunc=go)
  cached._arg_namespace = namespace
  cached._arg_region = region
  return cached
 return decorate

def cache_region ( region , * deco_args ) : cache = [ None ] def decorate ( func ) : namespace = util . func_namespace ( func ) def cached ( * args ) : reg = cache_regions [ region ] if ( not reg . get ( 'enabled' , True ) ) : return func ( * args ) if ( not cache [ 0 ] ) : if ( region not in cache_regions ) : raise BeakerException ( ( 'Cache region not configured: %s' % region ) ) cache [ 0 ] = Cache . _get_cache ( namespace , reg ) cache_key = ' ' . join ( map ( str , ( deco_args + args ) ) ) def go ( ) : return func ( * args ) return cache [ 0 ] . get_value ( cache_key , createfunc = go ) cached . _arg_namespace = namespace cached . _arg_region = region return cached return decorate
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 .