From 9e365fc5e3badccafb72fd3ba39271f3924d9ddc Mon Sep 17 00:00:00 2001 From: JasonGiedymin Date: Sat, 2 Apr 2011 00:32:48 -0400 Subject: [PATCH 1/2] HACK: patch to allow Django 1.3.x and prior fallback compatability. --- nexus_memcache/conf.py | 43 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/nexus_memcache/conf.py b/nexus_memcache/conf.py index 06de16c..c0c14d6 100644 --- a/nexus_memcache/conf.py +++ b/nexus_memcache/conf.py @@ -1,3 +1,44 @@ +''' +To avoid backend validation for custom backends, supply 'NEXUS_MEMCACHE_BACKEND'. +Validation only occurs for 'default' entries supplied by Django 1.3.x. +Fallback to 'CACHE_BACKEND' on Django Versions prior to 1.3.x. + +Currently does try to loop through found memcached backends, easier +to just set the key described above manually however. + +I consider this a hack until Nexus-Memcache is able to read the entire +CACHES dictionary (nexus_modules.py) in place of the work done up front +here. +''' + +import django from django.conf import settings +from django.core import cache + + +_NEXUS_MEM_KEY = 'NEXUS_MEMCACHE_BACKEND' + +_NEXUS_IMPORT_ERR_MSG = 'Nexus Memcached default backend improperly configured. ' + \ + 'Try NEXUS_MEMCACHE_BACKEND in settings.py.' + + +class NexusCacheImproperlyConfigured(Exception): + ''' + Nexus Memcached backend declaration is somehow improperly configured. + Try to set NEXUS_MEMCACHE_BACKEND in settings.py manually. + ''' + pass + + +if float(django.get_version()) < 1.3: # For all versions prior to 1.3.x + BACKEND = getattr(settings, NEXUS_MEM_KEY, settings.CACHE_BACKEND) +else: # For all versions 1.3.x and after + # Does a defined default exist? + if not settings.CACHES.has_key(cache.DEFAULT_CACHE_ALIAS): + raise NexusCacheImproperlyConfigured(_NEXUS_IMPORT_ERR_MSG) + else: # Grab all the backends + backend, location, params = cache.parse_backend_conf(cache.DEFAULT_CACHE_ALIAS) + location_string = ';'.join(location) + BACKEND = ('memcached://%s/' % location_string) + -BACKEND = getattr(settings, 'NEXUS_MEMCACHE_BACKEND', settings.CACHE_BACKEND) From 25718620caa5df22d9bb5d42b98cebc8f5621d62 Mon Sep 17 00:00:00 2001 From: JasonGiedymin Date: Sat, 2 Apr 2011 01:07:24 -0400 Subject: [PATCH 2/2] Oops, wrong key const. You can tell I don't use Django 1.2... --- nexus_memcache/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nexus_memcache/conf.py b/nexus_memcache/conf.py index c0c14d6..99bb4ce 100644 --- a/nexus_memcache/conf.py +++ b/nexus_memcache/conf.py @@ -31,7 +31,7 @@ class NexusCacheImproperlyConfigured(Exception): if float(django.get_version()) < 1.3: # For all versions prior to 1.3.x - BACKEND = getattr(settings, NEXUS_MEM_KEY, settings.CACHE_BACKEND) + BACKEND = getattr(settings, _NEXUS_MEM_KEY, settings.CACHE_BACKEND) else: # For all versions 1.3.x and after # Does a defined default exist? if not settings.CACHES.has_key(cache.DEFAULT_CACHE_ALIAS):