From 46ee03da027c7c13da22f76d688b64555f8d4685 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Mon, 18 Nov 2024 20:40:22 +0100 Subject: [PATCH] Solution --- app/main.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index 68287892..9b644ae6 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,17 @@ -from typing import Callable +from typing import Callable, Any def cache(func: Callable) -> Callable: - # Write your code here - pass + data = {} + + def inner(*args) -> Any: + if args not in data: + print("Calculating new result") + result = func(*args) + data[args] = result + return result + if args in data: + print("Getting from cache") + return data[args] + + return inner