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: 15 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
from typing import Callable
from functools import wraps
from typing import Any


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

@wraps(func)
def wrapper(*args, **kwargs) -> Any:
sorted_kwargs = tuple(sorted(kwargs.items()))
key = (args, sorted_kwargs)
if key not in results_cache:
print("Calculating new result")
results_cache[key] = func(*args, **kwargs)
else:
print("Getting from cache")
return results_cache[key]
return wrapper
Loading