def memoize_in_request_cache(request_cache_attr_name=None):
 def _decorator(func):
  'Outer method decorator.'
  @functools.wraps(func)
  def _wrapper(self, *args, **kwargs):
   '\n            Wraps a method to memoize results.\n            '
   request_cache = getattr(self, request_cache_attr_name, None)
   if request_cache:
    cache_key = '&'.join([hashvalue(arg) for arg in args])
    if (cache_key in request_cache.data.setdefault(func.__name__, {})):
     return request_cache.data[func.__name__][cache_key]
    result = func(self, *args, **kwargs)
    request_cache.data[func.__name__][cache_key] = result
    return result
   else:
    return func(self, *args, **kwargs)
  return _wrapper
 return _decorator

def memoize_in_request_cache ( request_cache_attr_name = None ) : def _decorator ( func ) : @ functools . wraps ( func ) def _wrapper ( self , * args , ** kwargs ) : request_cache = getattr ( self , request_cache_attr_name , None ) if request_cache : cache_key = '&' . join ( [ hashvalue ( arg ) for arg in args ] ) if ( cache_key in request_cache . data . setdefault ( func . __name__ , { } ) ) : return request_cache . data [ func . __name__ ] [ cache_key ] result = func ( self , * args , ** kwargs ) request_cache . data [ func . __name__ ] [ cache_key ] = result return result else : return func ( self , * args , ** kwargs ) return _wrapper return _decorator
memoize a method calls results in the request_cache if theres one .