Skip to content

Instantly share code, notes, and snippets.

@timotta
Created January 31, 2011 17:09
Show Gist options
  • Save timotta/804386 to your computer and use it in GitHub Desktop.
Save timotta/804386 to your computer and use it in GitHub Desktop.
def memoize(func):
def inner(*args):
objeto = args[0]
if not '__cache_memoize__' in objeto.__dict__:
objeto.__cache_memoize__ = {}
chave = tuple([func]) + tuple(args)
if chave in objeto.__cache_memoize__:
return objeto.__cache_memoize__[chave]
else:
ret = func(*args)
objeto.__cache_memoize__[chave] = ret
return ret
return inner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment