def cache_timer_decorator(fn_name):
 def wrap(fn):
  def timed_fn(self, *a, **kw):
   use_timer = kw.pop('use_timer', True)
   try:
    getattr(g, 'log')
   except TypeError:
    return fn(self, *a, **kw)
   if (use_timer and self.stats):
    publish = (random.random() < g.stats.CACHE_SAMPLE_RATE)
    cache_name = self.stats.cache_name
    timer_name = ('cache.%s.%s' % (cache_name, fn_name))
    timer = g.stats.get_timer(timer_name, publish)
    timer.start()
   else:
    timer = None
   result = fn(self, *a, **kw)
   if timer:
    timer.stop()
   return result
  return timed_fn
 return wrap

def cache_timer_decorator ( fn_name ) : def wrap ( fn ) : def timed_fn ( self , * a , ** kw ) : use_timer = kw . pop ( 'use_timer' , True ) try : getattr ( g , 'log' ) except TypeError : return fn ( self , * a , ** kw ) if ( use_timer and self . stats ) : publish = ( random . random ( ) < g . stats . CACHE_SAMPLE_RATE ) cache_name = self . stats . cache_name timer_name = ( 'cache.%s.%s' % ( cache_name , fn_name ) ) timer = g . stats . get_timer ( timer_name , publish ) timer . start ( ) else : timer = None result = fn ( self , * a , ** kw ) if timer : timer . stop ( ) return result return timed_fn return wrap
use to decorate cachechain operations so timings will be recorded .