Bird
0
0

Examine this Django cache code snippet:

medium📝 Debug Q6 of 15
Django - Caching
Examine this Django cache code snippet:
cache.set('session', 'active')
cache.delete('session')
value = cache.get('session', default='none')

What will be the value of value after execution?
A'active'
B'none'
CNone
DRaises an exception
Step-by-Step Solution
Solution:
  1. Step 1: Set cache key 'session'

    The key 'session' is set to 'active'.
  2. Step 2: Delete the cache key

    The key 'session' is deleted, so it no longer exists in cache.
  3. Step 3: Retrieve with default

    Calling cache.get('session', default='none') returns 'none' because the key was deleted.
  4. Final Answer:

    'none' -> Option B
  5. Quick Check:

    Deleted keys return default value on get [OK]
Quick Trick: Deleted cache keys return the default value if provided [OK]
Common Mistakes:
MISTAKES
  • Expecting the old value after deletion
  • Assuming get returns None without default

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes