From 55de6d2394502fdd8082707f5cdd4117da4859bb Mon Sep 17 00:00:00 2001 From: Adam Halka Date: Wed, 23 Oct 2024 21:03:24 +0200 Subject: [PATCH 1/2] Solution --- app/main.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index 68287892..2862473b 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,19 @@ -from typing import Callable +from typing import Callable, Any +from functools import wraps def cache(func: Callable) -> Callable: - # Write your code here - pass + cache_storage = {} + + @wraps(func) + def wrapper(*args) -> Any: + if args in cache_storage: + print("Getting from cache") + return cache_storage[args] + else: + print("Calculating new result") + result = func(*args) + cache_storage[args] = result + return result + + return wrapper \ No newline at end of file From e779df78cb8c3a18354f99152f6230fa5c30ea31 Mon Sep 17 00:00:00 2001 From: Adam Halka Date: Wed, 23 Oct 2024 21:05:03 +0200 Subject: [PATCH 2/2] Remade --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 2862473b..74f43b55 100644 --- a/app/main.py +++ b/app/main.py @@ -16,4 +16,4 @@ def wrapper(*args) -> Any: cache_storage[args] = result return result - return wrapper \ No newline at end of file + return wrapper