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