From d1c4c101eac51fae67266a67bce3b5c4734dd9ab Mon Sep 17 00:00:00 2001 From: Lytillis Date: Thu, 28 Sep 2023 16:27:12 +0300 Subject: [PATCH] Cache decorator solution --- app/main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 68287892..a8cb6406 100644 --- a/app/main.py +++ b/app/main.py @@ -2,5 +2,13 @@ def cache(func: Callable) -> Callable: - # Write your code here - pass + stored_runs = {} + + def wrapper(*args): + if args in stored_runs: + print("Getting from cache") + return stored_runs[args] + print("Calculating new result") + stored_runs.update({args: func(*args)}) + return stored_runs[args] + return wrapper