Bird
0
0

You want to optimize a Flask service function that retrieves user profiles by adding caching. Which method best aligns with the service layer pattern?

hard📝 Conceptual Q8 of 15
Flask - Ecosystem and Patterns
You want to optimize a Flask service function that retrieves user profiles by adding caching. Which method best aligns with the service layer pattern?
AAdd caching logic directly in the Flask route before calling the service
BImplement caching inside the service function using a cache decorator
CStore cached data in the client-side JavaScript
DBypass the service layer and cache database queries in the model
Step-by-Step Solution
Solution:
  1. Step 1: Understand service layer responsibility

    The service layer handles business logic including caching.
  2. Step 2: Evaluate caching placement

    Caching inside the service function keeps logic centralized and reusable.
  3. Final Answer:

    Implement caching inside the service function using a cache decorator -> Option B
  4. Quick Check:

    Caching belongs inside service layer [OK]
Quick Trick: Cache inside service layer for best practice [OK]
Common Mistakes:
MISTAKES
  • Placing caching in routes instead of service
  • Caching on client side which is unrelated
  • Bypassing service layer breaks separation of concerns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes