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