Bird
0
0

Which of the following is the correct way to set a cache value in Django using the low-level cache API?

easy📝 Syntax Q12 of 15
Django - Caching
Which of the following is the correct way to set a cache value in Django using the low-level cache API?
Acache.add('key', 'value', 300)
Bcache.set('key', 'value', timeout=300)
Ccache.save('key', 'value', 300)
Dcache.put('key', 'value', timeout=300)
Step-by-Step Solution
Solution:
  1. Step 1: Recall Django cache API method

    The correct method to store a value is cache.set(key, value, timeout).
  2. Step 2: Check method parameters

    cache.set uses named timeout parameter, unlike add or put which are incorrect here.
  3. Final Answer:

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

    cache.set() stores cache with timeout [OK]
Quick Trick: Remember: cache.set(key, value, timeout) is standard [OK]
Common Mistakes:
MISTAKES
  • Using cache.add which only adds if key missing
  • Using non-existent methods like cache.save or cache.put
  • Passing timeout as positional instead of named argument

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes