-
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
Cache Decorator Solution #1331
base: master
Are you sure you want to change the base?
Cache Decorator Solution #1331
Conversation
app/main.py
Outdated
@cache | ||
def long_time_func(a_a: int, b_b: int, c_c: int) -> int: | ||
return (a_a ** b_b ** c_c) % (a_a * c_c) | ||
|
||
|
||
@cache | ||
def long_time_func_2(n_tuple: tuple, power: int) -> int: | ||
return [number ** power for number in n_tuple] | ||
|
||
|
||
long_time_func(1, 2, 3) | ||
long_time_func(2, 2, 3) | ||
long_time_func_2((5, 6, 7), 5) | ||
long_time_func(1, 2, 3) | ||
long_time_func_2((5, 6, 7), 10) | ||
long_time_func_2((5, 6, 7), 10) | ||
|
||
# Calculating new result | ||
# Calculating new result | ||
# Calculating new result | ||
# Getting from cache | ||
# Calculating new result | ||
# Getting from cache |
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.
please remove your custom tests
app/main.py
Outdated
|
||
def wrapper(*args, **kwargs) -> Any: |
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.
use functools.wraps
app/main.py
Outdated
res_dict = {} | ||
|
||
def wrapper(*args, **kwargs) -> Any: | ||
if args in res_dict: |
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.
as key for cache_dict usetuple with *args, **kwargs and name of function since all of this will define unique call of function.
Co-authored-by: Vasyl Smutok <[email protected]>
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.
Great!
No description provided.