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 #1420

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

valerii-kashpur
Copy link

  • added chache

- added chache
Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Great job on implementing the caching decorator! 🎉 Your code meets the task requirements and constraints effectively. While the implementation is correct, consider converting args to a hashable type to avoid potential issues with mutable types as keys in the cache. Keep up the good work and happy coding! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨


def wrapper(*args, **kwargs) -> Callable:
nonlocal cache_storage
if args in cache_storage:

Choose a reason for hiding this comment

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

Using args as a key in cache_storage can lead to issues if args contains mutable types like lists. Consider converting args to a hashable type, such as a tuple of tuples, to ensure it can be used as a dictionary key.

return cache_storage[args]
else:
func_result = func(*args, **kwargs)
cache_storage.update({args: func_result})

Choose a reason for hiding this comment

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

Similar to the previous comment, ensure that args is converted to a hashable type before using it as a key in cache_storage.

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.

3 participants