Build a decorator that caches results for a limited time and then recomputes.
Constraints
Example
>>> import time
>>> @memoize_ttl(2)
... def add(a, b):
... print('computing...')
... return a + b
>>> add(1, 2)
computing...
3
>>> add(1, 2)
3
>>> time.sleep(2.1)
>>> add(1, 2)
computing...
3
Recent Submissions
No submissions yet — hit Run Tests to try!
Hints