From dfcee6873e2ed4c4fe96d9b3ce646bd5dddb07a8 Mon Sep 17 00:00:00 2001 From: aristokrat18 Date: Thu, 17 Jul 2014 15:24:17 -0400 Subject: [PATCH] Updating to reflect changes in 1.7 Django 1.7 changed the PyLibMCCache definition to remove _local and move _client (previously referenced as _local.client) up a level. --- django_elasticache/memcached.py | 39 ++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/django_elasticache/memcached.py b/django_elasticache/memcached.py index d301580..6cf2427 100644 --- a/django_elasticache/memcached.py +++ b/django_elasticache/memcached.py @@ -58,14 +58,33 @@ def _cache(self): # PylibMC uses cache options as the 'behaviors' attribute. # It also needs to use threadlocals, because some versions of # PylibMC don't play well with the GIL. - client = getattr(self._local, 'client', None) - if client: + + # Django < 1.7 + if hasattr(self, '_local'): + + client = getattr(self._local, 'client', None) + if client: + return client + + client = self._lib.Client(self.get_cluster_nodes) + if self._options: + client.behaviors = self._options + + self._local.client = client + + return client + + # Django == 1.7 + else: + + client = getattr(self, '_client', None) + if client: + return client + + client = self._lib.Client(self.get_cluster_nodes) + if self._options: + client.behaviors = self._options + + self._client = client + return client - - client = self._lib.Client(self.get_cluster_nodes) - if self._options: - client.behaviors = self._options - - self._local.client = client - - return client