Bird
0
0

You want to cache a Django view that shows user-specific data but still use per-view caching. Which approach correctly applies caching without showing wrong data to users?

hard📝 Application Q15 of 15
Django - Caching
You want to cache a Django view that shows user-specific data but still use per-view caching. Which approach correctly applies caching without showing wrong data to users?
ACache the view globally and add user ID in the URL to separate cache keys
BUse <code>@cache_page(120)</code> without changes; caching will separate users automatically
CUse <code>@cache_page(120)</code> and add <code>Vary: Cookie</code> header to cache per user session
DDo not use caching on user-specific views at all
Step-by-Step Solution
Solution:
  1. Step 1: Understand caching user-specific data risks

    Global caching can show one user's data to others if not separated.
  2. Step 2: Use Vary header to separate cache by user session

    Adding Vary: Cookie tells cache to store different versions per user session cookie.
  3. Final Answer:

    Use @cache_page(120) and add Vary: Cookie header to cache per user session -> Option C
  4. Quick Check:

    Vary header separates cache by user [OK]
Quick Trick: Use Vary header to separate cache per user [OK]
Common Mistakes:
MISTAKES
  • Assuming caching separates users automatically
  • Avoiding caching user views unnecessarily
  • Adding user ID in URL without proper cache keys

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes