-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Task done #769
base: master
Are you sure you want to change the base?
Task done #769
Changes from 3 commits
d22c801
606626b
1ac2a7f
fb19ab4
45a7644
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,5 +2,17 @@ | |||||
|
||||||
|
||||||
def cache(func: Callable) -> Callable: | ||||||
# Write your code here | ||||||
pass | ||||||
cache_history = dict() | ||||||
|
||||||
def wrapper(*args) -> str: | ||||||
# func_name = f"{func}({args})" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove comment |
||||||
|
||||||
if f"{func}({args})" in cache_history: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Why do you need func? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the function name to the cache because I moved the cache to outside the decorator. In this case arguments could be repeated for different functions. I corrected it as you recommended. |
||||||
print("Getting from cache") | ||||||
else: | ||||||
print("Calculating new result") | ||||||
cache_history[f"{func}({args})"] = func(*args) | ||||||
|
||||||
return cache_history[f"{func}({args})"] | ||||||
|
||||||
return wrapper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.