Compression¶
django-cachex supports pluggable compression to reduce memory usage. Compression is only applied to values larger than 256 bytes by default.
Configuration¶
CACHES = {
"default": {
"BACKEND": "django_cachex.cache.ValkeyCache",
"LOCATION": "valkey://127.0.0.1:6379/1",
"OPTIONS": {
"compressor": "django_cachex.compressors.zstd.ZStdCompressor",
}
}
}
Available Compressors¶
| Compressor | Speed | Ratio | Dependency |
|---|---|---|---|
django_cachex.compressors.zlib.ZlibCompressor |
Medium | Good | Built-in |
django_cachex.compressors.gzip.GzipCompressor |
Medium | Good | Built-in |
django_cachex.compressors.lzma.LzmaCompressor |
Slow | Best | Built-in |
django_cachex.compressors.lz4.Lz4Compressor |
Fast | Moderate | django-cachex[lz4] |
django_cachex.compressors.zstd.ZStdCompressor |
Fast | Good | django-cachex[zstd] (Python < 3.14) |
Install optional dependencies:
Zstandard uses the built-in compression.zstd module on Python 3.14+.
Fallback for Migration¶
Specify a list of compressors to safely migrate between formats. The first is used for writing, all are tried for reading: