Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
venv/
.pytest_cache/
**__pycache__/
.venv
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
deco_cache = {}

@wraps(func)
def wrapper(*args: Any, **kwargs: Any) -> Any:
key = tuple(args) + tuple(kwargs.items())
Comment on lines 5 to +10
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a sample comment

if key not in deco_cache:
deco_cache[key] = func(*args, **kwargs)
print("Calculating new result")
else:
print("Getting from cache")
return deco_cache[key]
return wrapper
Loading