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