Commits

Mike Bayer committed 9326ca7

- support "min_compress_len" and "memcached_expire_time"
with python-memcached backend. Tests courtesy
Justin Azoff #3

Comments (0)

Files changed (4)

+0.2.3
+=====
+- support "min_compress_len" and "memcached_expire_time"
+  with python-memcached backend.  Tests courtesy
+  Justin Azoff #3
+
 0.2.2
 =====
 - add Redis backend, courtesy Ollie Rutherfurd

dogpile/cache/__init__.py

-__version__ = '0.2.2'
+__version__ = '0.2.3'
 
 from .region import CacheRegion, register_backend, make_region

dogpile/cache/backends/memcached.py

     def delete(self, key):
         self.client.delete(key)
 
-class PylibmcBackend(GenericMemcachedBackend):
+class MemcacheArgs(object):
+    """Mixin which provides support for the 'time' argument to set(), 
+    'min_compress_len' to other methods.
+    
+    """
+    def __init__(self, arguments):
+        self.min_compress_len = arguments.get('min_compress_len', 0)
+
+        self.set_arguments = {}
+        if "memcached_expire_time" in arguments:
+            self.set_arguments["time"] = \
+                            arguments["memcached_expire_time"]
+        if "min_compress_len" in arguments:
+            self.set_arguments["min_compress_len"] = \
+                            arguments["min_compress_len"]
+        super(MemcacheArgs, self).__init__(arguments)
+
+class PylibmcBackend(MemcacheArgs, GenericMemcachedBackend):
     """A backend for the 
     `pylibmc <http://sendapatch.se/projects/pylibmc/index.html>`_ 
     memcached client.
     def __init__(self, arguments):
         self.binary = arguments.get('binary', False)
         self.behaviors = arguments.get('behaviors', {})
-        self.min_compress_len = arguments.get('min_compress_len', 0)
-
-        self.set_arguments = {}
-        if "memcached_expire_time" in arguments:
-            self.set_arguments["time"] = \
-                            arguments["memcached_expire_time"]
-        if "min_compress_len" in arguments:
-            self.set_arguments["min_compress_len"] = \
-                            arguments["min_compress_len"]
         super(PylibmcBackend, self).__init__(arguments)
 
 
                         behaviors=self.behaviors
                     )
 
-class MemcachedBackend(GenericMemcachedBackend):
+class MemcachedBackend(MemcacheArgs, GenericMemcachedBackend):
     """A backend using the standard `Python-memcached <http://www.tummy.com/Community/software/python-memcached/>`_
     library.
     

tests/cache/test_memcached_backend.py

 
 from dogpile.cache.backends.memcached import GenericMemcachedBackend
 from dogpile.cache.backends.memcached import PylibmcBackend
-class MockMemcachedBackend(GenericMemcachedBackend):
+from dogpile.cache.backends.memcached import MemcachedBackend
+
+class MockGenericMemcachedBackend(GenericMemcachedBackend):
+    def _imports(self):
+        pass
+
+    def _create_client(self):
+        return MockClient(self.url)
+
+class MockMemcacheBackend(MemcachedBackend):
     def _imports(self):
         pass
 
 
 class MemcachedArgstest(TestCase):
     def test_set_time(self):
-        backend = MockMemcachedBackend(arguments={'url':"foo", 
+        backend = MockMemcacheBackend(arguments={'url':"foo", 
                                 "memcached_expire_time":20})
         backend.set("foo", "bar")
         eq_(backend._clients.memcached.canary, [{"time":20}])
 
     def test_set_min_compress_len(self):
-        backend = MockMemcachedBackend(arguments={'url':"foo", 
+        backend = MockMemcacheBackend(arguments={'url':"foo", 
                                 "min_compress_len":20})
         backend.set("foo", "bar")
         eq_(backend._clients.memcached.canary, [{"min_compress_len":20}])
-    
+
 
 class LocalThreadTest(TestCase):
     def setUp(self):
         self._test_client_cleanup(10)
 
     def _test_client_cleanup(self, count):
-        backend = MockMemcachedBackend(arguments={'url':'foo'})
+        backend = MockGenericMemcachedBackend(arguments={'url':'foo'})
         canary = []
 
         def f():
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.