diff --git a/app/main.py b/app/main.py index 68287892..9bbd9905 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,19 @@ from typing import Callable +from functools import wraps def cache(func: Callable) -> Callable: - # Write your code here - pass + + results = dict({}) + + @wraps(func) + def wrapper(*args) -> callable: + if args in results: + print("Getting from cache") + return results[args] + else: + print("Calculating new result") + result = func(*args) + results[args] = result + return result + return wrapper