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