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
20 changes: 16 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
from typing import Callable
from typing import Any, Callable


def cache(func: Callable) -> Callable:
# Write your code here
pass
def cache(func: Callable[..., Any]) -> Callable[..., Any]:
cache_dict: dict = {}

def wrapper(*args: Any, **kwargs: Any) -> Any:
key = (args, tuple(sorted(kwargs.items())))

if key in cache_dict:
print("Getting from cache")
return cache_dict[key]

print("Calculating new result")
result = func(*args, **kwargs)
cache_dict[key] = result
return result
return wrapper
Loading