Skip to content

Instantly share code, notes, and snippets.

@wil
Created October 8, 2012 05:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wil/3850799 to your computer and use it in GitHub Desktop.
Save wil/3850799 to your computer and use it in GitHub Desktop.
Django 1.3 CACHE_BACKEND settings backward compatibility
# 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