From 6104f189bcd0609b0493e5486fcaebff946ef97f Mon Sep 17 00:00:00 2001 From: Vladyslav Date: Thu, 23 Jan 2025 20:19:01 +0100 Subject: [PATCH 1/3] Solution --- app/main.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index 68287892..1ab8eda8 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,19 @@ -from typing import Callable +from functools import wraps +from typing import Callable, Any, Tuple def cache(func: Callable) -> Callable: - # Write your code here - pass + cache_store = {} + + @wraps(func) + def wrapper(*args: Tuple[Any, ...]) -> Any: + if args in cache_store: + print("Getting from cache") + result = cache_store[args] + else: + print("Calculating new result") + result = func(*args) + cache_store[args] = result + return result + + return wrapper From 4ced435c3f72c413e33d2aa7837b20c99644d6b7 Mon Sep 17 00:00:00 2001 From: Vladyslav Date: Thu, 23 Jan 2025 20:25:04 +0100 Subject: [PATCH 2/3] Solution --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 1ab8eda8..94e6513a 100644 --- a/app/main.py +++ b/app/main.py @@ -16,4 +16,4 @@ def wrapper(*args: Tuple[Any, ...]) -> Any: cache_store[args] = result return result - return wrapper + return wrapper \ No newline at end of file From 06cd3e865f3aa16a6868765f6945a2a9ca76242f Mon Sep 17 00:00:00 2001 From: Vladyslav Date: Thu, 23 Jan 2025 20:26:43 +0100 Subject: [PATCH 3/3] Solution --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 94e6513a..1ab8eda8 100644 --- a/app/main.py +++ b/app/main.py @@ -16,4 +16,4 @@ def wrapper(*args: Tuple[Any, ...]) -> Any: cache_store[args] = result return result - return wrapper \ No newline at end of file + return wrapper