From 27fc61f7394a6256ba63e06c4ecb35d068494e2c Mon Sep 17 00:00:00 2001 From: Arsen Myroniuk Date: Sat, 21 Dec 2024 13:59:15 +0200 Subject: [PATCH] Solution --- app/main.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 68287892..ab195c98 100644 --- a/app/main.py +++ b/app/main.py @@ -2,5 +2,16 @@ def cache(func: Callable) -> Callable: - # Write your code here - pass + results = {} + + def inner(*args, **kwargs) -> func: + key = (args, tuple(sorted(kwargs.items()))) + if key not in results: + print("Calculating new result") + result = func(*args, **kwargs) + results[key] = result + return result + else: + print("Getting from cache") + return results[key] + return inner