Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
from typing import Callable
from typing import Callable, Any
from functools import wraps


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

@wraps(func)
def inner(*args: tuple, **kwargs: dict) -> Any:
Comment on lines +7 to +9
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don’t forget to use @functools.wraps.

data = args, tuple(kwargs.items())
if data not in cache_dict:
print("Calculating new result")
cache_dict[data] = func(*args, **kwargs)
else:
print("Getting from cache")
return cache_dict[data]
return inner
Loading