diff --git a/app/main.py b/app/main.py index 68287892..1ab8eda8 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,19 @@ -from typing import Callable +from functools import wraps +from typing import Callable, Any, Tuple def cache(func: Callable) -> Callable: - # Write your code here - pass + cache_store = {} + + @wraps(func) + def wrapper(*args: Tuple[Any, ...]) -> Any: + if args in cache_store: + print("Getting from cache") + result = cache_store[args] + else: + print("Calculating new result") + result = func(*args) + cache_store[args] = result + return result + + return wrapper