From adab3c3ca7b73a2076a331edf30a416ead3996fe Mon Sep 17 00:00:00 2001 From: Shcherbyna Svitlana Date: Sat, 7 Oct 2023 10:06:38 +0300 Subject: [PATCH 1/4] Solution --- app/main.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 68287892..9e26def9 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,16 @@ from typing import Callable +from typing import Any def cache(func: Callable) -> Callable: - # Write your code here - pass + args_dict = {} + + def saver(*args) -> Any: + if args in args_dict: + print("Getting from cache") + return args_dict[args] + else: + args_dict[args] = func(*args) + print("Calculating new result") + return args_dict[args] + return saver From d3617941ccfa76dafdb1d61bc5c960c45ee032f7 Mon Sep 17 00:00:00 2001 From: Shcherbyna Svitlana Date: Sun, 8 Oct 2023 11:20:39 +0300 Subject: [PATCH 2/4] Solution --- app/main.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index 9e26def9..7a78939c 100644 --- a/app/main.py +++ b/app/main.py @@ -9,8 +9,9 @@ def saver(*args) -> Any: if args in args_dict: print("Getting from cache") return args_dict[args] - else: - args_dict[args] = func(*args) - print("Calculating new result") - return args_dict[args] + + args_dict[args] = func(*args) + print("Calculating new result") + return args_dict[args] + return saver From 0de64772758b280ba9f3ef9bdb9135b661e52ec8 Mon Sep 17 00:00:00 2001 From: Shcherbyna Svitlana Date: Sun, 8 Oct 2023 16:48:59 +0300 Subject: [PATCH 3/4] Solution --- app/main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 7a78939c..a9dee500 100644 --- a/app/main.py +++ b/app/main.py @@ -1,5 +1,4 @@ -from typing import Callable -from typing import Any +from typing import Callable, Any def cache(func: Callable) -> Callable: From 2018e12b628a3e1d888785bec000eb3384a74064 Mon Sep 17 00:00:00 2001 From: Shcherbyna Svitlana Date: Sun, 8 Oct 2023 16:55:25 +0300 Subject: [PATCH 4/4] Solution --- app/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/main.py b/app/main.py index a9dee500..1aeae3be 100644 --- a/app/main.py +++ b/app/main.py @@ -1,9 +1,11 @@ from typing import Callable, Any +from functools import wraps def cache(func: Callable) -> Callable: args_dict = {} + @wraps(func) def saver(*args) -> Any: if args in args_dict: print("Getting from cache")