File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -58,14 +58,19 @@ def _cache(self):
5858 # PylibMC uses cache options as the 'behaviors' attribute.
5959 # It also needs to use threadlocals, because some versions of
6060 # PylibMC don't play well with the GIL.
61- client = getattr (self ._local , 'client' , None )
61+
62+ # instance to store cached version of client
63+ # in Django 1.7 use self
64+ # in Django < 1.7 use thread local
65+ container = getattr (self , '_local' , self )
66+ client = getattr (container , '_client' , None )
6267 if client :
6368 return client
6469
6570 client = self ._lib .Client (self .get_cluster_nodes )
6671 if self ._options :
6772 client .behaviors = self ._options
6873
69- self . _local . client = client
74+ container . _client = client
7075
7176 return client
Original file line number Diff line number Diff line change @@ -40,3 +40,18 @@ def test_split_servers(get_cluster_info):
4040 assert backend ._cache
4141 get_cluster_info .assert_called_once_with ('h' , '0' )
4242 backend ._lib .Client .assert_called_once_with (servers )
43+
44+
45+ @patch ('django.conf.settings' , global_settings )
46+ @patch ('django_elasticache.memcached.get_cluster_info' )
47+ def test_property_cache (get_cluster_info ):
48+ from django_elasticache .memcached import ElastiCache
49+ backend = ElastiCache ('h:0' , {})
50+ servers = ['h1:p' , 'h2:p' ]
51+ get_cluster_info .return_value = {
52+ 'nodes' : servers
53+ }
54+ backend ._lib .Client = Mock ()
55+ backend .set ('key1' , 'val' )
56+ backend .set ('key2' , 'val' )
57+ backend ._lib .Client .assert_called_once_with (servers )
You can’t perform that action at this time.
0 commit comments