From 1ec336f3cc75077776e3259bffdaf2261407e96e Mon Sep 17 00:00:00 2001 From: Alina Bondarenko Date: Wed, 11 Dec 2024 12:55:12 +0200 Subject: [PATCH] Solution --- app/main.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 68287892..d2bcf3d7 100644 --- a/app/main.py +++ b/app/main.py @@ -2,5 +2,15 @@ def cache(func: Callable) -> Callable: - # Write your code here - pass + cache_func = {} + def wrapper(*args, **kwargs) -> str: + key = (args, frozenset(kwargs.items())) + if key in cache_func: + print("Getting from cache") + return cache_func[key] + else: + print("Calculating new result") + result = func(*args, **kwargs) + cache_func[key] = result + return result + return wrapper