Skip to content

Commit

Permalink
'Solution'
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey-Dementyev committed Oct 5, 2024
1 parent 5891c38 commit 92d5f88
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
from typing import Callable
from functools import wraps


def cache(func: Callable) -> Callable:
# Write your code here
pass
cache_dict = {}

@wraps(func)
def wrapper(*args, **kwargs) -> Callable:
key = (args, tuple(kwargs.items()))

if key in cache_dict:
print("Getting from cache")
return cache_dict[key]
else:
print("Calculating new result")
cache_dict[key] = func(*args, **kwargs)
return cache_dict[key]

return wrapper

0 comments on commit 92d5f88

Please sign in to comment.