From 954ec53cc4d154e751ead69be8c4c63694517cb1 Mon Sep 17 00:00:00 2001 From: Lysenko Volodymyr Date: Fri, 22 May 2026 22:20:32 +0200 Subject: [PATCH 1/2] feat: implement cache decorator with internal storage --- app/main.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index 68287892f..cc0a376cb 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,22 @@ -from typing import Callable +from functools import wraps +from typing import Callable, Any def cache(func: Callable) -> Callable: - # Write your code here - pass + storage = {} + + @wraps(func) + def wrapper(*args, **kwargs) -> Any: + cache_key = (args, tuple(sorted(kwargs.items()))) + + if cache_key in storage: + print("Getting from cache") + return storage[cache_key] + + print("Calculating new result") + result = func(*args, **kwargs) + storage[cache_key] = result + + return result + + return wrapper \ No newline at end of file From 75ad21425bba8630e8821b9617d5dde58a58d6a5 Mon Sep 17 00:00:00 2001 From: Lysenko Volodymyr Date: Fri, 22 May 2026 22:56:16 +0200 Subject: [PATCH 2/2] fix: add newline at the end of main.py --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index cc0a376cb..ff60ff9dc 100644 --- a/app/main.py +++ b/app/main.py @@ -19,4 +19,4 @@ def wrapper(*args, **kwargs) -> Any: return result - return wrapper \ No newline at end of file + return wrapper