diff --git a/newcache.py b/newcache.py index 1a26e17..ef250cf 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) +CACHE_MIN_COMPRESS = getattr(settings, 'PYLIBMC_MIN_COMPRESS_LEN', 0) # Disabled +if CACHE_MIN_COMPRESS > 0 and not memcache.support_compression: + CACHE_MIN_COMPRESS = 0 + class Marker(object): pass @@ -130,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) + 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) @@ -160,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) + 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))