From 6afd04d4456835aa07202ef8e5f34776e30fe177 Mon Sep 17 00:00:00 2001 From: Josh Ourisman Date: Tue, 21 Feb 2012 14:39:08 -0500 Subject: [PATCH 1/4] =?UTF-8?q?Added=20support=20for=20pylibmc=20compressi?= =?UTF-8?q?on=20=C3=A0=20la=20jbalogh/django-pylibmc.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- newcache.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/newcache.py b/newcache.py index 1a26e17..357ae5b 100644 --- a/newcache.py +++ b/newcache.py @@ -36,6 +36,10 @@ CACHE_KEY_MODULE = getattr(settings, 'CACHE_KEY_MODULE', 'newcache') CACHE_HERD_TIMEOUT = getattr(settings, 'CACHE_HERD_TIMEOUT', 60) +MIN_COMPRESS = getattr(settings, 'PYLIBMC_MIN_COMPRESS_LEN', 0) # Disabled +if MIN_COMPRESS > 0 and not pylibmc.support_compression: + MIN_COMPRESS = 0 + class Marker(object): pass @@ -130,7 +134,7 @@ def add(self, key, value, timeout=None, herd=True): else: packed = value real_timeout = self._get_memcache_timeout(timeout) - return self._cache.add(key_func(key), packed, real_timeout) + return self._cache.add(key_func(key), packed, real_timeout, MIN_COMPRESSION) def get(self, key, default=None): encoded_key = key_func(key) @@ -160,7 +164,7 @@ def set(self, key, value, timeout=None, herd=True): else: packed = value real_timeout = self._get_memcache_timeout(timeout) - return self._cache.set(key_func(key), packed, real_timeout) + return self._cache.set(key_func(key), packed, real_timeout, MIN_COMPRESSINO) def delete(self, key): self._cache.delete(key_func(key)) From d23c001da8a16244f4ce7fd000ba76e356b43874 Mon Sep 17 00:00:00 2001 From: Josh Ourisman Date: Tue, 21 Feb 2012 14:41:10 -0500 Subject: [PATCH 2/4] Fixed mismatched variable name; changed to CACHE_MIN_COMPRESS for consistency. --- newcache.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/newcache.py b/newcache.py index 357ae5b..f7bc598 100644 --- a/newcache.py +++ b/newcache.py @@ -36,9 +36,9 @@ CACHE_KEY_MODULE = getattr(settings, 'CACHE_KEY_MODULE', 'newcache') CACHE_HERD_TIMEOUT = getattr(settings, 'CACHE_HERD_TIMEOUT', 60) -MIN_COMPRESS = getattr(settings, 'PYLIBMC_MIN_COMPRESS_LEN', 0) # Disabled -if MIN_COMPRESS > 0 and not pylibmc.support_compression: - MIN_COMPRESS = 0 +CACHE_MIN_COMPRESS = getattr(settings, 'PYLIBMC_MIN_COMPRESS_LEN', 0) # Disabled +if CACHE_MIN_COMPRESS > 0 and not pylibmc.support_compression: + CACHE_MIN_COMPRESS = 0 class Marker(object): pass @@ -134,7 +134,7 @@ def add(self, key, value, timeout=None, herd=True): else: packed = value real_timeout = self._get_memcache_timeout(timeout) - return self._cache.add(key_func(key), packed, real_timeout, MIN_COMPRESSION) + return self._cache.add(key_func(key), packed, real_timeout, CACHE_MIN_COMPRESS) def get(self, key, default=None): encoded_key = key_func(key) @@ -164,7 +164,7 @@ def set(self, key, value, timeout=None, herd=True): else: packed = value real_timeout = self._get_memcache_timeout(timeout) - return self._cache.set(key_func(key), packed, real_timeout, MIN_COMPRESSINO) + return self._cache.set(key_func(key), packed, real_timeout, CACHE_MIN_COMPRESS) def delete(self, key): self._cache.delete(key_func(key)) From 02e46b52cbf685bf2b2971ee9477963a36723bf8 Mon Sep 17 00:00:00 2001 From: Josh Ourisman Date: Tue, 21 Feb 2012 14:46:40 -0500 Subject: [PATCH 3/4] pylibmc is imported as memcache --- newcache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/newcache.py b/newcache.py index f7bc598..d749c6b 100644 --- a/newcache.py +++ b/newcache.py @@ -37,7 +37,7 @@ CACHE_HERD_TIMEOUT = getattr(settings, 'CACHE_HERD_TIMEOUT', 60) CACHE_MIN_COMPRESS = getattr(settings, 'PYLIBMC_MIN_COMPRESS_LEN', 0) # Disabled -if CACHE_MIN_COMPRESS > 0 and not pylibmc.support_compression: +if CACHE_MIN_COMPRESS > 0 and not memcache.support_compression: CACHE_MIN_COMPRESS = 0 class Marker(object): From a840e4f47b2d4c00dbaedc782360f01933789a60 Mon Sep 17 00:00:00 2001 From: Josh Ourisman Date: Tue, 21 Feb 2012 14:49:17 -0500 Subject: [PATCH 4/4] Only pass compression argument if using_pylibmc is True. --- newcache.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/newcache.py b/newcache.py index d749c6b..ef250cf 100644 --- a/newcache.py +++ b/newcache.py @@ -134,7 +134,10 @@ def add(self, key, value, timeout=None, herd=True): else: packed = value real_timeout = self._get_memcache_timeout(timeout) - return self._cache.add(key_func(key), packed, real_timeout, CACHE_MIN_COMPRESS) + args = [key_func(key), packed, real_timeout] + if using_pylibmc is True: + args.append(CACHE_MIN_COMPRESS) + return self._cache.add(*args) def get(self, key, default=None): encoded_key = key_func(key) @@ -164,7 +167,10 @@ def set(self, key, value, timeout=None, herd=True): else: packed = value real_timeout = self._get_memcache_timeout(timeout) - return self._cache.set(key_func(key), packed, real_timeout, CACHE_MIN_COMPRESS) + args = [key_func(key), packed, real_timeout] + if using_pylibmc is True: + args.append(CACHE_MIN_COMPRESS) + return self._cache.set(*args) def delete(self, key): self._cache.delete(key_func(key))