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


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

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