Refs #110 -- Don't use cached session storage without a central cache

This commit is contained in:
Raphael Michel
2015-12-03 22:07:30 +01:00
parent 411eb3c60f
commit 8dd7b581d5

View File

@@ -87,16 +87,17 @@ CACHES = {
'LOCATION': 'unique-snowflake', 'LOCATION': 'unique-snowflake',
} }
} }
REAL_CACHE_USED = False
SESSION_ENGINE = None
HAS_MEMCACHED = config.has_option('memcached', 'location') HAS_MEMCACHED = config.has_option('memcached', 'location')
if HAS_MEMCACHED: if HAS_MEMCACHED:
REAL_CACHE_USED = True
CACHES['default'] = { CACHES['default'] = {
'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache', 'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',
'LOCATION': config.get('memcached', 'location'), 'LOCATION': config.get('memcached', 'location'),
} }
SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"
HAS_REDIS = config.has_option('redis', 'location') HAS_REDIS = config.has_option('redis', 'location')
if HAS_REDIS: if HAS_REDIS:
CACHES['redis'] = { CACHES['redis'] = {
@@ -108,10 +109,16 @@ if HAS_REDIS:
} }
if not HAS_MEMCACHED: if not HAS_MEMCACHED:
CACHES['default'] = CACHES['redis'] CACHES['default'] = CACHES['redis']
REAL_CACHE_USED = True
if config.getboolean('redis', 'sessions', fallback=False): if config.getboolean('redis', 'sessions', fallback=False):
SESSION_ENGINE = "django.contrib.sessions.backends.cache" SESSION_ENGINE = "django.contrib.sessions.backends.cache"
SESSION_CACHE_ALIAS = "redis" SESSION_CACHE_ALIAS = "redis"
if not SESSION_ENGINE and REAL_CACHE_USED:
SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"
else:
SESSION_ENGINE = "django.contrib.sessions.backends.db"
HAS_CELERY = config.has_option('celery', 'broker') HAS_CELERY = config.has_option('celery', 'broker')
if HAS_CELERY: if HAS_CELERY:
BROKER_URL = config.get('celery', 'broker') BROKER_URL = config.get('celery', 'broker')