Bird
0
0

Given this template code:

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

What happens when two different users visit the page?
AEach user sees a cached version unique to their user.id
BBoth users see the same cached content regardless of user.id
CCache is ignored and content renders fresh every time
DAn error occurs because user.id cannot be used as a key
Step-by-Step Solution
Solution:
  1. Step 1: Understand cache key with variables

    The cache key here includes user.id, so the cache stores separate fragments per user.
  2. Step 2: Predict behavior for different users

    Different users have different user.id, so each gets their own cached fragment.
  3. Final Answer:

    Each user sees a cached version unique to their user.id -> Option A
  4. Quick Check:

    Cache key with variable = unique cache per user [OK]
Quick Trick: Cache keys with variables create separate cached versions [OK]
Common Mistakes:
MISTAKES
  • Assuming one cache for all users
  • Thinking cache ignores variables
  • Believing user.id causes errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes