Skip to content

Implement cache decorator#2265

Open
GabrielB-B wants to merge 1 commit into
mate-academy:masterfrom
GabrielB-B:solution/cache-decorator
Open

Implement cache decorator#2265
GabrielB-B wants to merge 1 commit into
mate-academy:masterfrom
GabrielB-B:solution/cache-decorator

Conversation

@GabrielB-B
Copy link
Copy Markdown

Implemented the cache decorator.

Changes:

  • Added cache storage for decorated function calls
  • Returned cached results for repeated immutable arguments
  • Printed required messages for cached and new calculations
  • Verified with pytest and flake8

Copy link
Copy Markdown

@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.

Review Summary

Your implementation correctly satisfies all the task requirements. The cache decorator properly stores results using a dictionary with keys generated from function arguments, prints the required messages for both cache hits and misses, and maintains separate cache storage for each decorated function through closure. As a best practice improvement, consider adding @functools.wraps(func) above your inner wrapper function definition. This preserves the original function's metadata like __name__ and __doc__, which is standard Python convention for decorators. This doesn't affect functionality but improves debugging and introspection. Overall, the solution is functional, clean, and meets all stated requirements. Good work!


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

Footnotes

  1. Rate AI review example

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