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