Bird
0
0

Given this template code:

medium📝 component behavior Q13 of 15
Django - Caching
Given this template code:
{% cache 600 'menu' user.id %}
  • Home
  • Profile
{% endcache %}

What happens if user.id changes?
AA new cache entry is created for the new user.id
BThe cached fragment is reused regardless of user.id
CThe cache is cleared completely
DAn error occurs because user.id cannot be used
Step-by-Step Solution
Solution:
  1. Step 1: Understand cache key with extra parameters

    Extra parameters after the key string are used to create a unique cache key per value.
  2. Step 2: Effect of changing user.id on cache

    When user.id changes, Django creates a new cache entry for that user, so the fragment is cached separately.
  3. Final Answer:

    A new cache entry is created for the new user.id -> Option A
  4. Quick Check:

    Cache key + params = unique cache per user [OK]
Quick Trick: Extra params create unique cache keys [OK]
Common Mistakes:
MISTAKES
  • Assuming cache ignores extra parameters
  • Thinking cache clears all entries on param change
  • Believing user.id cannot be used in cache tag

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes