Mike Bayer avatar Mike Bayer committed e2bca8f

use a memoize here to simplify backend structure

Comments (0)

Files changed (2)

dogpile/cache/backends/memcached.py

         self.memcached_expire_time = arguments.get(
                                         'memcached_expire_time', 0)
 
-        backend = self
-        class ClientPool(util.threading.local):
-            def __init__(self):
-                self.memcached = backend._create_client()
-
-        self._clients = ClientPool()
-
-
     def _imports(self):
         """client library imports go here."""
         raise NotImplementedError()
         """Creation of a Client instance goes here."""
         raise NotImplementedError()
 
+    @util.memoized_property
+    def _clients(self):
+        backend = self
+        class ClientPool(util.threading.local):
+            def __init__(self):
+                self.memcached = backend._create_client()
+
+        return ClientPool()
+
     @property
     def client(self):
         """Return the memcached client.

tests/test_memcached_backend.py

             t.start()
         for t in threads:
             t.join()
-        eq_(canary, [i + 2 for i in xrange(count)])
-        eq_(MockClient.number_of_clients, 1)
+        eq_(canary, [i + 1 for i in xrange(count)])
+        eq_(MockClient.number_of_clients, 0)
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.