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