Bird
0
0

Which of the following is the correct syntax to set a cache value with a timeout of 300 seconds?

easy📝 Syntax Q3 of 15
Django - Caching
Which of the following is the correct syntax to set a cache value with a timeout of 300 seconds?
Acache.set('key', 300, 'value')
Bcache.set('key', 'value', timeout=300)
Ccache.set('key', timeout=300)
Dcache.set('key', 'value', expire=300)
Step-by-Step Solution
Solution:
  1. Step 1: Recall the set() method signature

    The set() method accepts key, value, and an optional timeout parameter named 'timeout'.
  2. Step 2: Check parameter order and names

    B has incorrect argument order, C is missing the value argument, D uses invalid 'expire'.
  3. Final Answer:

    cache.set('key', 'value', timeout=300) -> Option B
  4. Quick Check:

    Set cache with timeout = cache.set(key, value, timeout=seconds) [OK]
Quick Trick: Use timeout=seconds to set cache expiry [OK]
Common Mistakes:
MISTAKES
  • Swapping value and timeout arguments
  • Using 'expire' instead of 'timeout'
  • Incorrect argument order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes