Bird
0
0

Given this code snippet, what will be the output?

medium📝 component behavior Q4 of 15
Django - Caching
Given this code snippet, what will be the output?
from django.core.cache import cache
cache.set('item', 'value', timeout=10)
cache.delete('item')
result = cache.get('item')
print(result)
Avalue
BNone
CTimeoutError
DKeyError
Step-by-Step Solution
Solution:
  1. Step 1: Analyze cache.set and cache.delete

    cache.set stores 'value' under 'item' key, then cache.delete removes 'item' key.
  2. Step 2: Check cache.get after deletion

    cache.get('item') returns None because the key was deleted.
  3. Final Answer:

    None -> Option B
  4. Quick Check:

    Deleted key returns None on get [OK]
Quick Trick: Deleted cache keys return None on retrieval [OK]
Common Mistakes:
MISTAKES
  • Expecting the old value after deletion
  • Thinking deletion raises an error
  • Confusing timeout with deletion effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes