Bird
0
0

Which of the following is the correct way to define a simple in-memory cache backend in Django's CACHES setting?

easy📝 Syntax Q12 of 15
Django - Caching
Which of the following is the correct way to define a simple in-memory cache backend in Django's CACHES setting?
A'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}
B'default': {'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', 'LOCATION': '/var/tmp/django_cache'}
C'default': {'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', 'LOCATION': '127.0.0.1:11211'}
D'default': {'BACKEND': 'django.core.cache.backends.db.DatabaseCache', 'LOCATION': 'my_cache_table'}
Step-by-Step Solution
Solution:
  1. Step 1: Identify the in-memory cache backend

    The in-memory cache backend in Django is LocMemCache, which stores cache in local memory.
  2. Step 2: Match the correct syntax

    'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'} correctly sets BACKEND to django.core.cache.backends.locmem.LocMemCache without needing a LOCATION.
  3. Final Answer:

    'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'} -> Option A
  4. Quick Check:

    In-memory cache = LocMemCache [OK]
Quick Trick: LocMemCache is in-memory, no location needed [OK]
Common Mistakes:
MISTAKES
  • Adding LOCATION for LocMemCache unnecessarily
  • Confusing file-based or DB cache for in-memory
  • Using wrong backend string casing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes