From 8ebeefebd8646f5de1f12c22bcd923e787feebf8 Mon Sep 17 00:00:00 2001 From: Katarzyna Ochmanska Date: Wed, 27 Nov 2024 20:34:12 +0100 Subject: [PATCH] Solution --- app/main.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index 68287892..8a8e1991 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,19 @@ -from typing import Callable +from typing import Callable, Any +from functools import wraps def cache(func: Callable) -> Callable: - # Write your code here - pass + cache_store = {} + + @wraps(func) + def wrapper(*args, **kwargs) -> Any: + key = (args, frozenset(kwargs.items())) + if key in cache_store: + print("Getting from cache") + return cache_store[key] + else: + print("Calculating new result") + result = func(*args, **kwargs) + cache_store[key] = result + return result + return wrapper