Skip to content
Closed
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
39 changes: 29 additions & 10 deletions django_elasticache/memcached.py
Original file line number Diff line number Diff line change
Expand Up @@ -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