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