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