def request_cached(f):
 def wrapper(*args, **kwargs):
  '\n        Wrapper function to decorate with.\n        '
  converted_args = map(str, args)
  converted_kwargs = map(str, reduce(list.__add__, map(list, sorted(kwargs.iteritems())), []))
  cache_keys = (([f.__module__, f.func_name] + converted_args) + converted_kwargs)
  cache_key = '.'.join(cache_keys)
  rcache = RequestCache.get_request_cache()
  if (cache_key in rcache.data):
   return rcache.data.get(cache_key)
  else:
   result = f(*args, **kwargs)
   rcache.data[cache_key] = result
   return result
 return wrapper

def request_cached ( f ) : def wrapper ( * args , ** kwargs ) : converted_args = map ( str , args ) converted_kwargs = map ( str , reduce ( list . __add__ , map ( list , sorted ( kwargs . iteritems ( ) ) ) , [ ] ) ) cache_keys = ( ( [ f . __module__ , f . func_name ] + converted_args ) + converted_kwargs ) cache_key = '.' . join ( cache_keys ) rcache = RequestCache . get_request_cache ( ) if ( cache_key in rcache . data ) : return rcache . data . get ( cache_key ) else : result = f ( * args , ** kwargs ) rcache . data [ cache_key ] = result return result return wrapper
a decorator for wrapping a function and automatically handles caching its return value .