Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nexus_memcache/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import django
from django.conf import settings

BACKEND = getattr(settings, 'NEXUS_MEMCACHE_BACKEND', getattr(settings, 'CACHE_BACKEND', None))
33 changes: 27 additions & 6 deletions nexus_memcache/nexus_modules.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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):
Expand Down