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