From 3479ee4b98b1edbb89dab23b103eeb0ef82c80af Mon Sep 17 00:00:00 2001 From: Dmytro Date: Sat, 9 Nov 2024 20:45:49 +0200 Subject: [PATCH] 'Solution_v1.00' --- app/main.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 68287892..815e2012 100644 --- a/app/main.py +++ b/app/main.py @@ -2,5 +2,17 @@ def cache(func: Callable) -> Callable: - # Write your code here - pass + cache_dict: dict = {} + + def wrapper(*args) -> int: + + template = ",".join(str(arg) for arg in args) + if template in cache_dict: + print("Getting from cache") + else: + cache_dict[template] = func(*args) + print("Calculating new result") + + return cache_dict[template] + + return wrapper