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