diff --git a/app/main.py b/app/main.py index 68287892..4d74cbdd 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 + storage = {} + + def wrapper(*args: Any, **kwargs: Any) -> Any: + key = (args, tuple(sorted(kwargs.items()))) + + if key in storage: + print("Getting from cache") + return storage[key] + else: + result = func(*args, **kwargs) + storage[key] = result + print("Calculating new result") + return result + + return wrapper +