From c83c0e59e7bba06450fd89a8454e17bf1aacfea6 Mon Sep 17 00:00:00 2001 From: Serhii Date: Mon, 18 Nov 2024 16:21:40 +0100 Subject: [PATCH] solution to py-cache-decorator --- app/main.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 68287892..d6b66354 100644 --- a/app/main.py +++ b/app/main.py @@ -2,5 +2,16 @@ def cache(func: Callable) -> Callable: - # Write your code here - pass + + tmp_cache = {} + + def inner(*args) -> None: + if args in tmp_cache: + print("Getting from cache") + return tmp_cache[args] + else: + print("Calculating new result") + result = func(*args) + tmp_cache[args] = result + return result + return inner