Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for data compression (gzip) #301

Open
eunchong opened this issue Nov 6, 2024 · 1 comment
Open

Support for data compression (gzip) #301

eunchong opened this issue Nov 6, 2024 · 1 comment

Comments

@eunchong
Copy link

eunchong commented Nov 6, 2024

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?

@alessio-locatelli
Copy link

alessio-locatelli commented Nov 6, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants