Skip to content

Instantly share code, notes, and snippets.

@embayer
Created February 24, 2016 20:36
Show Gist options
  • Save embayer/91ba82647521443123fb to your computer and use it in GitHub Desktop.
Save embayer/91ba82647521443123fb to your computer and use it in GitHub Desktop.
caching decorator
def memoize(f):
cache = {}
def memoized_function(*args):
if args not in cache:
cache[args] = f(*args)
return cache[args]
memoized_function.cache = cache
return memoized_function
@memoize
def foo(a, b):
return a + b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment