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