From 1ab7c5b0fe6e38e7de521cc12ca0403e875dd402 Mon Sep 17 00:00:00 2001 From: Mykyta Kovalenko Date: Sat, 1 Feb 2025 18:28:48 +0200 Subject: [PATCH 1/2] Solution --- app/main.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 68287892..00da70ee 100644 --- a/app/main.py +++ b/app/main.py @@ -2,5 +2,15 @@ def cache(func: Callable) -> Callable: - # Write your code here - pass + cache_dic = {} + + def wrapper(*args) -> None: + if args in cache_dic: + print("Getting from cache") + return cache_dic[args] + else: + print("Calculating new result") + res = func(*args) + cache_dic[args] = res + return res + return wrapper From ab1f3898fd82036d1416d90dca0a9fd02dea5ac1 Mon Sep 17 00:00:00 2001 From: Mykyta Kovalenko Date: Sat, 1 Feb 2025 18:31:35 +0200 Subject: [PATCH 2/2] fix type annotation --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 00da70ee..933d33f1 100644 --- a/app/main.py +++ b/app/main.py @@ -4,7 +4,7 @@ def cache(func: Callable) -> Callable: cache_dic = {} - def wrapper(*args) -> None: + def wrapper(*args): if args in cache_dic: print("Getting from cache") return cache_dic[args]