[Answered ]-Setting multiple Django cache backends

2👍

In order to use multiple cache backends in Django they both need to be present in the CACHES dictionary. There are several ways you can do that, but your second snippet isn’t one of them.

You could do this, but I’ve never seen anyone do it in practice:

from django.conf.global_settings import CACHES

CACHES['filemem'] = {
        'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
        'LOCATION': '/var/tmp/django_cache',
      }

Usually people explicitly declare all the CACHE backends they will use, like this:

CACHES = {
  'default': {
    'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
  },
  'filemem': {
    'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
    'LOCATION': '/var/tmp/django_cache',
  }
} 

But in this snippet you are overwriting the caches dict with only the filemem cache:

CACHES = {
  'filemem': {
    'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
    'LOCATION': '/var/tmp/django_cache',
  }
} 

Leave a comment