Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Support for Django 1.3 CACHES Configuration #3

Open
wants to merge 3 commits into from

2 participants

@streeter

Robust support for the cache backends introduced in Django 1.3.

@gdehaan

Hi,
We are using CACHES/Django 1.3 as well.
Will these commits be merged?
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 19, 2011
  1. @streeter
  2. @streeter

    Fix a type error.

    streeter authored
Commits on Apr 11, 2012
  1. @streeter

    Merge remote-tracking branch 'upstream/master'

    streeter authored
    Conflicts:
    	nexus_memcache/conf.py
This page is out of date. Refresh to see the latest.
Showing with 28 additions and 6 deletions.
  1. +1 −0  nexus_memcache/conf.py
  2. +27 −6 nexus_memcache/nexus_modules.py
View
1  nexus_memcache/conf.py
@@ -1,3 +1,4 @@
+import django
from django.conf import settings
BACKEND = getattr(settings, 'NEXUS_MEMCACHE_BACKEND', getattr(settings, 'CACHE_BACKEND', None))
View
33 nexus_memcache/nexus_modules.py
@@ -1,8 +1,13 @@
import socket
import warnings
+import django
from django.core.cache import get_cache, parse_backend_uri
+if django.get_version() >= "1.3":
+ from django.core.cache import parse_backend_conf
+from django.core.cache.backends.base import InvalidCacheBackendError
from django.utils.datastructures import SortedDict
+from django.utils import importlib
import nexus
@@ -14,12 +19,28 @@ class MemcacheModule(nexus.NexusModule):
def get_caches(self):
caches = []
- schema, hosts, params = parse_backend_uri(conf.BACKEND)
- for host in hosts.split(';'):
- try:
- caches.append((host, get_cache('%s://%s?%s' % (schema, host, params))._cache))
- except Exception, e:
- self.logger.exception(e)
+ if isinstance(conf.BACKEND, dict) and django.get_version() >= "1.3":
+ for name in conf.BACKEND.keys():
+ backend, location, params = parse_backend_conf(name)
+ if ';' in location:
+ location = location.split(';')
+ try:
+ mod_path, cls_name = backend.rsplit('.', 1)
+ mod = importlib.import_module(mod_path)
+ backend_cls = getattr(mod, cls_name)
+ for host in location:
+ caches.append((host, backend_cls(host, params)._cache))
+ except Exception, e:
+ self.logger.exception(e)
+ elif '://' in conf.BACKEND:
+ schema, hosts, prams = parse_backend_uri(conf.BACKEND)
+ for host in hosts.split(';'):
+ try:
+ caches.append((host, get_cache('%s://%s?%s' % (schema, host, params))._cache))
+ except Exception, e:
+ self.logger.exception(e)
+ else:
+ self.logger.warning('No cache was configured')
return caches
def get_stats(self, timeout=5):
Something went wrong with that request. Please try again.