Bird
0
0

How would you configure Django to use multiple cache backends, one for default caching and another for sessions, with the session cache having a different timeout?

hard📝 Application Q9 of 15
Django - Caching
How would you configure Django to use multiple cache backends, one for default caching and another for sessions, with the session cache having a different timeout?
A{ 'default': { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache' }, 'sessions': { 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', 'LOCATION': '/tmp/session_cache' } }
B{ 'default': { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', 'TIMEOUT': 300 }, 'sessions': { 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', 'LOCATION': '/tmp/session_cache', 'TIMEOUT': 600 } }
C{ 'default': { 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', 'LOCATION': '/tmp/default_cache', 'TIMEOUT': 600 }, 'sessions': { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', 'TIMEOUT': 300 } }
D{ 'default': { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', 'TIMEOUT': null }, 'sessions': { 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', 'LOCATION': '/tmp/session_cache', 'TIMEOUT': null } }
Step-by-Step Solution
Solution:
  1. Step 1: Understand multiple cache alias configuration

    Django allows multiple caches by defining different aliases like 'default' and 'sessions'.
  2. Step 2: Check each cache backend and timeout

    'default' uses locmem with 300 seconds timeout; 'sessions' uses filebased with 600 seconds timeout.
  3. Step 3: Validate LOCATION for filebased cache

    Filebased cache requires a valid directory path for LOCATION.
  4. Final Answer:

    Correctly configures two caches with different backends and timeouts -> Option B
  5. Quick Check:

    Multiple caches with distinct TIMEOUTs and backends [OK]
Quick Trick: Use different aliases with separate TIMEOUTs for multiple caches [OK]
Common Mistakes:
MISTAKES
  • Omitting LOCATION for filebased cache
  • Mixing backend types incorrectly
  • Not setting different TIMEOUTs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes