Bird
0
0

Which of the following is the correct way to cache a Flask route response for 60 seconds using Flask-Caching?

easy📝 Syntax Q12 of 15
Flask - Performance Optimization
Which of the following is the correct way to cache a Flask route response for 60 seconds using Flask-Caching?
A@cache.cache(60) def my_route(): return 'Hello'
B@cache.cache(timeout=60) def my_route(): return 'Hello'
C@cache.cached(timeout=60) def my_route(): return 'Hello'
D@cached(60) def my_route(): return 'Hello'
Step-by-Step Solution
Solution:
  1. Step 1: Recall Flask-Caching decorator syntax

    The correct decorator is @cache.cached with a named argument timeout=60 to set cache duration.
  2. Step 2: Check each option

    @cache.cached(timeout=60) def my_route(): return 'Hello' uses correct decorator and syntax. Options A and B use cache.cache which is invalid. @cached(60) def my_route(): return 'Hello' misses the cache. instance prefix.
  3. Final Answer:

    @cache.cached(timeout=60) def my_route(): return 'Hello' -> Option C
  4. Quick Check:

    Use @cache.cached(timeout=seconds) [OK]
Quick Trick: Use @cache.cached with timeout= seconds [OK]
Common Mistakes:
MISTAKES
  • Using @cache.cache instead of @cache.cached
  • Omitting the cache. prefix (@cached instead of @cache.cached)
  • Using positional timeout argument

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes