From d2cb5bfc2eb30b85acf55a81b4b0be13a0a0ac7a Mon Sep 17 00:00:00 2001 From: Vitalii Ivanchenko Date: Mon, 11 Nov 2024 23:29:09 +0200 Subject: [PATCH] Solution --- .flake8 | 2 +- app/main.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.flake8 b/.flake8 index d7459204..99d2e123 100644 --- a/.flake8 +++ b/.flake8 @@ -4,4 +4,4 @@ ignore = E203, E266, W503, ANN002, ANN003, ANN101, ANN102, ANN401, N807, N818 max-line-length = 79 max-complexity = 18 select = B,C,E,F,W,T4,B9,ANN,Q0,N8,VNE -exclude = venv, tests +exclude = .venv, tests diff --git a/app/main.py b/app/main.py index 68287892..33a5be2f 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,16 @@ -from typing import Callable +from typing import Callable, Dict, Tuple, Any def cache(func: Callable) -> Callable: - # Write your code here - pass + cache_storage: Dict[Tuple, Any] = {} + + def wrapper(*args) -> any: + if args in cache_storage: + print("Getting from cache") + return cache_storage[args] + else: + print("Calculating new result") + result = func(*args) + cache_storage[args] = result + return result + return wrapper