Bird
0
0

What is wrong with this cache invalidation approach?

medium📝 Debug Q7 of 15
Django - Caching
What is wrong with this cache invalidation approach?
cache.set('user_42', user_data, timeout=300)
# Later in code
cache.clear()
Acache.clear() removes all cache keys, not just 'user_42'
Bcache.set timeout is too short
Ccache.clear() does not remove any keys
Dcache.set key name is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Understand cache.clear() effect

    cache.clear() removes all keys from the cache, not just one.
  2. Step 2: Identify problem with approach

    Using cache.clear() to invalidate one key is too broad and removes unrelated cached data.
  3. Final Answer:

    cache.clear() removes all cache keys, not just 'user_42' -> Option A
  4. Quick Check:

    cache.clear() clears entire cache [OK]
Quick Trick: Use cache.delete() to remove one key, not cache.clear() [OK]
Common Mistakes:
MISTAKES
  • Using cache.clear() to delete single keys
  • Thinking cache.clear() only affects one key
  • Assuming cache.set key names have restrictions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes