What's the fast method to compress Python objects (list, dictionary, string, etc) before saving them to cache and decompress after read from cache?
I'm using Django and I hope to add compress/decompress support directly in Django's cache backend which makes it available to all my Django apps.
I looked into django/core/cache/backends/memcached.py
import cmemcache as memcache
class CacheClass(BaseCache):
def __init__(self, server, params):
BaseCache.__init__(self, params)
self._cache = memcache.Client(server.split(';'))
def get(self, key, default=None):
val = self._cache.get(smart_str(key))
if val is None:
return default
return val
def set(self, key, value, timeout=0):
self._cache.set(smart_str(key), value, self._get_memcache_timeout(timeout))
Looks like pickle/unpickle is done by cmemcache library. I dont know where to put the compress/decompress code.