What is a quick way to compress Python objects (list, dictionary, string, etc.) before storing them in the cache and unpacking them after reading from the cache?
I am using Django, and I hope to add support for compression / decompression directly to the backend of the Django cache, which makes it accessible to all my Django applications.
I looked at 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))
It seems that the brine / unickle is executed by the cmemcache library. I don’t know where to put the compression / decompression code.
source
share