From d00f7d9202d2b34e04df3eea01bee393292c3cf1 Mon Sep 17 00:00:00 2001 From: Atom-gnomov Date: Sat, 21 Dec 2024 09:31:18 +0200 Subject: [PATCH] task completed --- app/main.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 68287892..2aaac9b3 100644 --- a/app/main.py +++ b/app/main.py @@ -2,5 +2,16 @@ def cache(func: Callable) -> Callable: - # Write your code here - pass + cache_save = {} + + def wrapper(*args, **kwargs) -> any: + cache_key = (args, tuple(sorted(kwargs.items()))) + if cache_key in cache_save: + print("Getting from cache") + return cache_save[cache_key] + else: + print("Calculating new result") + result = func(*args, **kwargs) + cache_save[cache_key] = result + return result + return wrapper