diff --git a/app/main.py b/app/main.py index 68287892..581c9201 100644 --- a/app/main.py +++ b/app/main.py @@ -2,5 +2,18 @@ def cache(func: Callable) -> Callable: - # Write your code here - pass + save_result = {} + + def inner(*args, **kwargs) -> Callable: + key_in_save_result = (func.__name__, args, tuple(kwargs.items())) + + if key_in_save_result in save_result: + print("Getting from cache") + return save_result[key_in_save_result] + + print("Calculating new result") + result = func(*args, **kwargs) + save_result[key_in_save_result] = result + return result + + return inner