Search code examples
djangocachingmemcacheddjango-cache

Config for 'Cache' in settings.CACHES missing


I have configured cache in settings.py in my Django project as follows:

CACHE_MIDDLEWARE_ALIAS = 'Cache'
CACHE_MIDDLEWARE_SECONDS = 60
CACHE_MIDDLEWARE_KEY_PREFIX = ''
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211',
    }
}

Cache service is running after I typed: $ memcached -p 11211 &

But when I try to run server, the following error shows up: django.core.cache.backends.base.InvalidCacheBackendError: Could not find config for 'Cache' in settings.CACHES

What I am doing wrong?


Solution

  • The CACHE_MIDDLEWARE_ALIAS setting tells the django middleware which cache to use: https://docs.djangoproject.com/en/3.1/ref/settings/#cache-middleware-alias

    Here it is set to 'Cache' but there is no cache of that name in your CACHES setting. You probably don't want a different alias and should just use the default of 'default' so just remove that setting.