Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active January 25, 2019 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/af6d3e3a5fe48f86a33e176264cf0116 to your computer and use it in GitHub Desktop.
Save deque-blog/af6d3e3a5fe48f86a33e176264cf0116 to your computer and use it in GitHub Desktop.
@functools.lru_cache(maxsize=2)
def long_computation(arg):
print("Long computation", arg)
return ...
for arg in [1,2,3] * 2:
long_computation(arg)
# Will print (only cache misses!)
"Long computation 1"
"Long computation 2"
"Long computation 3"
"Long computation 1"
"Long computation 2"
"Long computation 3"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment