Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

OleksandrSasha
Copy link

No description provided.

app/main.py Outdated
Comment on lines 20 to 42
@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
Copy link
Contributor

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
Comment on lines 6 to 7

def wrapper(*args, **kwargs) -> Any:
Copy link
Contributor

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:
Copy link
Contributor

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.

@OleksandrSasha OleksandrSasha requested a review from vsmutok October 4, 2024 20:31
app/main.py Outdated Show resolved Hide resolved
Co-authored-by: Vasyl Smutok <[email protected]>
@OleksandrSasha OleksandrSasha requested a review from vsmutok October 4, 2024 20:58
Copy link
Contributor

@vsmutok vsmutok left a comment

Choose a reason for hiding this comment

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

Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants