def memoized_with_request(request_func, request_index=0):
 def wrapper(func):
  memoized_func = memoized(func)
  @functools.wraps(func)
  def wrapped(*args, **kwargs):
   args = list(args)
   request = args.pop(request_index)
   args.insert(request_index, request_func(request))
   return memoized_func(*args, **kwargs)
  return wrapped
 return wrapper

def memoized_with_request ( request_func , request_index = 0 ) : def wrapper ( func ) : memoized_func = memoized ( func ) @ functools . wraps ( func ) def wrapped ( * args , ** kwargs ) : args = list ( args ) request = args . pop ( request_index ) args . insert ( request_index , request_func ( request ) ) return memoized_func ( * args , ** kwargs ) return wrapped return wrapper
decorator for caching functions which receive a request argument memoized functions with a request argument are memoized only during the rendering of a single view because the request argument is a new request instance on each view .