Support for data compression (gzip)
Hi @Krukov!
I'm currently using cashews with Redis as the backend storage. I noticed that the library uses pickle for serialization when storing values in Redis.
I'm wondering if there are any plans to support data compression (like gzip) during the serialization process? This could potentially reduce:
- Storage space in Redis
- Network bandwidth usage during Redis communications
If there are no plans to add compression support, I'd appreciate understanding the reasoning behind this decision. Would there be any technical challenges or performance concerns?
Any type of compression is already supported via the middleware pattern. You must revisit that section in the documentation.
A simplified example:
async def compression_middleware(call, command, backend, *args, **kwargs):
if cmd == Command.GET:
return decompress(await call(*args, **kwargs))
if cmd == Command.SET:
kwargs["value"] = compress(kwargs["value"])
return await call(*args, **kwargs)
cache.setup(..., middlewares=(compression_middleware, ))
@Krukov Should I mention this in the README to lower the barrier of entry?
@alessio-locatelli Thanks for answering. Probably we can mention this example as one of possible issue that can be fixed by middleware , Also middlewares like this can be a part of contrib module
Hm, looks like middlewares have access only to a raw value, not a serialized/pickled once. So maybe it is a good feature request to add compression for picked values