Return a function like f that remembers and reuses results of past calls.
481946
def memo(f):
    ""
    table = {}
    def memo_f(*args):
        try:
            return table[args]
        except KeyError:
            table[args] = value = f(*args)
            return value
    return memo_f
493859
def memoize(f):
    
    cache = {}

    @wraps(f)
    def inner(arg):
        if arg not in cache:
            cache[arg] = f(arg)
        return cache[arg]
    return inner
221747
def memoize(func):
    
    cache = {}

    @functools.wraps(func)
    def wrapper(*args):
        key = "__".join(str(arg) for arg in args)
        if key not in cache:
            cache[key] = func(*args)
        return cache[key]
    return wrapper
821296
def before_func_accept_retry_state(fn):
    """"""
    if not six.callable(fn):
        return fn

    if func_takes_retry_state(fn):
        return fn

    @_utils.wraps(fn)
    def wrapped_before_func(retry_state):
        # func, trial_number, trial_time_taken
        warn_about_non_retry_state_deprecation('before', fn, stacklevel=4)
        return fn(
            retry_state.fn,
            retry_state.attempt_number,
        )
    return wrapped_before_func
345093
def cached(f):
    

    cache = f.cache = {}

    @functools.wraps(f)
    def decorator(*args, **kwargs):
        key = str(args) + str(kwargs)
        if key not in cache:
            cache[key] = f(*args, **kwargs)
        return cache[key]
    return decorator
219981
def memoize(function):
    
    cache = {}
    @functools.wraps(function)
    def _memoize(*args):
        if args in cache:
            return cache[args]
        result = function(*args)
        cache[args] = result
        return result
    return function
708730
def cached(size):
    """"""
    def decorator(func):
        cached_func = _Cached(func, size)
        return lambda *a, **kw: cached_func(*a, **kw)
    return decorator
1253933
function memoize(fn) {
  const dataProp = '__data__.string.__data__',
    memFn = _.memoize.apply(_, _.slice(arguments)),
    report = _.throttle(reportMemoryLeak, minute),
    controlFn = function () {
      const result = memFn.apply(null, _.slice(arguments));

      if (_.size(_.get(memFn, `cache.${dataProp}`)) >= memoryLeakThreshold) {
        report(fn, _.get(memFn, `cache.${dataProp}`));
      }

      return result;
    };

  Object.defineProperty(controlFn, 'cache', defineWritable({
    get() { return memFn.cache; },
    set(value) { memFn.cache = value; }
  }));

  return controlFn;
}
261546
def update(self, function):
    """"""
    with self.lock:
      oldValue = self.value
      self.value = function(oldValue)
      return oldValue, self.value
519848
def cached_generator(function):
    """"""
    cache_variable = '_cached_' + function.__name__
    @wraps(function)
    def function_wrapper(obj, *args, **kwargs):
        # values are cached in a list stored in the object
        try:
            for item in getattr(obj, cache_variable):
                yield item
        except AttributeError:
            setattr(obj, cache_variable, [])
            cache = getattr(obj, cache_variable)
            for item in function(obj, *args, **kwargs):
                cache.append(item)
                yield item
    return function_wrapper
446637
def retry_call(func, cleanup=lambda: None, retries=0, trap=()):
	
	attempts = count() if retries == float('inf') else range(retries)
	for attempt in attempts:
		try:
			return func()
		except trap:
			cleanup()

	return func()
784518
def memoize_by_args(func):
    """"""
    memory = {}

    @functools.wraps(func)
    def memoized(*args):
        if args not in memory.keys():
            value = func(*args)
            memory[args] = value

        return memory[args]

    return memoized
416521
def cached(fn, size=32):
    ''' '''
    assert callable(fn)
    assert isinstance(size, int)
    return overload(fn)(lru_cache(size, typed=True)(fn))
951400
def simple_cache(func):
    
    saved_results = {}

    def wrapper(cls, module):
        if module in saved_results:
            return saved_results[module]
        saved_results[module] = func(cls, module)
        return saved_results[module]
    return wrapper
479691
def Cache(fn):
   
   def fnCache(*args, **kwargs):
      """ Cache function """
      key = (args and tuple(args) or None,
             kwargs and frozenset(kwargs.items()) or None)
      if key not in fn.__cached__:
         fn.__cached__[key] = cache = fn(*args, **kwargs)
      else:
         cache = fn.__cached__[key]
      return cache

   def ResetCache():
      """ Reset cache """
      fn.__cached__ = {}

   setattr(fn, "__cached__", {})
   setattr(fn, "__resetcache__", ResetCache)
   fnCache.__name__ = fn.__name__
   fnCache.__doc__ = fn.__doc__
   fnCache.__dict__.update(fn.__dict__)
   return fnCache
1351141
def singleton(func):
    

    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        if wrapper.__call_state__ == CALLED:
            return
        ret = func(*args, **kwargs)
        wrapper.__call_state__ = CALLED
        return ret

    def reset():
        wrapper.__call_state__ = NOT_CALLED

    wrapper.reset = reset
    reset()

    # save original func to be able to patch and restore multiple times from
    # unit tests
    wrapper.__original_func = func
    return wrapper
6317
def memoize(f):
    
    class memodict(dict):

        def __getitem__(self, *key):
            return dict.__getitem__(self, key)

        def __missing__(self, key):
            ret = self[key] = f(*key)
            return ret

    return memodict().__getitem__