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