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


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

@wraps(func)
def wrapper(*args, **kwargs) -> Any:
cache_key = (args, tuple(sorted(kwargs.items())))

if cache_key in storage:
print("Getting from cache")
return storage[cache_key]

print("Calculating new result")
result = func(*args, **kwargs)
storage[cache_key] = result

return result

return wrapper
Loading