Skip to content

Instantly share code, notes, and snippets.

@rtorresve
Created September 20, 2019 22:53
Show Gist options
  • Save rtorresve/018de3fc0b072369625575e2cad9f1a7 to your computer and use it in GitHub Desktop.
Save rtorresve/018de3fc0b072369625575e2cad9f1a7 to your computer and use it in GitHub Desktop.
Using python cache
import time
from functools import lru_cache
@lru_cache()
def task(a,b):
print('Init task')
time.sleep(2)
return a + b
task.cache_clear()
start = time.time()
print(task(10,10))
print(task(10,10))
print(task(10,15))
print(task(10,10))
print(task(10,10))
print(task(10,10))
print(task(10,15))
print(f'total time {time.time() - start}')
print(task.cache_info())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment