Created
October 8, 2012 05:00
-
-
Save wil/3850799 to your computer and use it in GitHub Desktop.
Django 1.3 CACHE_BACKEND settings backward compatibility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This allows you to maintain your Django cache settings in Django 1.3 style i.e. settings.CACHE | |
# and convert it to the old settings.CACHE_BACKEND url so that you can run it under Django 1.2 or earlier | |
from django.core.exceptions import ImproperlyConfigured | |
CACHE_BACKEND_MAP = { | |
'django.core.cache.backends.db.DatabaseCache': 'db', | |
'django.core.cache.backends.dummy.DummyCache': 'dummy', | |
'django.core.cache.backends.filebased.FileBasedCache': 'file', | |
'django.core.cache.backends.locmem.LocMemCache': 'locmem', | |
'django.core.cache.backends.memcached.MemcachedCache': 'memcached' | |
# 'django.core.cache.backends.memcached.PyLibMCCache': not in < Django 1.2 | |
} | |
def convert_cache(config): | |
v = CACHE_BACKEND_MAP.get(config['BACKEND']) | |
if not v: | |
if config['BACKEND'].endswith('.CacheClass'): | |
v = config['BACKEND'][:-11] | |
else: | |
raise ImproperlyConfigured("unknown cache backend %s" % config['BACKEND']) | |
loc = config.get('LOCATION', '') | |
if not isinstance(loc, basestring): | |
loc = ';'.join(loc) | |
url = '%s://%s' % (v, loc) | |
### TODO: handle TIMEOUT, OPTIONS, KEY_PREFIX, VERSION, KEY_FUNCTION | |
return url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment