diff --git a/app/main.py b/app/main.py index 68287892..6aa9b137 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,21 @@ -from typing import Callable +from typing import Callable, Any, Dict, Tuple, Hashable def cache(func: Callable) -> Callable: - # Write your code here - pass + cache_store: Dict[Callable, Dict[Tuple[Hashable, ...], Any]] = {} + + def wrapper(*args, **kwargs) -> Any: + if func not in cache_store: + cache_store[func] = {} + key = (args, frozenset(kwargs.items())) + + if key in cache_store[func]: + print("Getting from cache") + return cache_store[func][key] + + print("Calculating new result") + result = func(*args, **kwargs) + cache_store[func][key] = result + return result + + return wrapper diff --git a/checklist.md b/checklist.md index e1cbafc2..83ffb14b 100644 --- a/checklist.md +++ b/checklist.md @@ -1,4 +1,4 @@ -# Сheck Your Code Against the Following Points +v# Сheck Your Code Against the Following Points ## Code Efficiency