A specialized, lightweight Django cache backend for Valkey.
Project description
django-vcache
A fast, async-native Django cache backend for Valkey (and Redis). Opinionated and secure by default.
It powers the GlitchTip open-source error tracking platform.
Why django-vcache?
- Fast — Rust I/O driver with msgpack serialization (via ormsgpack). 13x faster than Django's built-in RedisCache under concurrent ASGI load.
- Async-native — True async I/O, not
sync_to_asyncthread-pool wrappers. Single multiplexed connection handles all concurrency. - Secure by default — No pickle. Msgpack cannot execute arbitrary code on deserialization. No special configuration needed.
- Efficient — One multiplexed connection for both sync and async. No connection pool to tune. Automatic zstd compression for large values.
- Python 3.14 ready — Uses stdlib
compression.zstdon 3.14+, no third-party compression dependency needed.
Benchmarks
Measured on Python 3.14 with granian ASGI server, 300 concurrent connections, 30 seconds, 2ms network RTT. Each request performs 6 cache operations (get, get_many, set, set compressed, incr, get compressed).
| django-vcache | Django RedisCache | Δ | |
|---|---|---|---|
| Requests/sec | 1,921 | 111 | 17x faster |
| Avg latency | 156 ms | 2,659 ms | 17x lower |
| Peak RSS | 125 MB | 356 MB | −65% |
| Valkey connections | 2 | 2,694 |
Django's built-in RedisCache wraps every async call in sync_to_async, spawning a thread per operation. Under load this creates thousands of connections and unbounded memory growth. django-vcache uses a single multiplexed connection with native async I/O.
Installation
pip install django-vcache
Usage
Update your settings.py to configure the cache backend:
CACHES = {
"default": {
"BACKEND": "django_vcache.backend.ValkeyCache",
"LOCATION": "valkey://your-valkey-host:6379/1",
},
}
You can then use Django's cache framework as usual:
from django.core.cache import cache
cache.set('my_key', 'my_value', 30)
value = cache.get('my_key')
API
django-vcache implements the full Django cache API with native async variants (aget, aset, etc.). All standard methods work as documented by Django:
get, set, add, delete, touch, incr, decr, has_key, get_many, set_many, delete_many, get_or_set, clear
Extras beyond Django
These methods extend the standard Django cache API:
lock(key, timeout=None, blocking=True, ...) / alock(...) — Distributed locking via Valkey. Not available in cluster mode.
with cache.lock("my-lock", timeout=10):
# exclusive access
...
async with cache.alock("my-lock", timeout=10):
...
get_raw_client() — Access the underlying Rust driver instance for operations not covered by the Django cache API. Reuses the existing connection.
client = cache.get_raw_client()
Atomic incr/decr
incr and decr use native Redis INCRBY/DECRBY commands. If the key does not exist, it is created with the delta value (Redis behavior). This is atomic and safe for concurrent counters.
Serialization
Values are serialized with msgpack (via ormsgpack) by default. Large values (>1KB by default) are compressed with zstd. Integer values are stored as raw strings to support native INCRBY.
For projects that need to cache arbitrary Python objects (Django models, custom classes, etc.), a pickle serializer is available:
"OPTIONS": {
"SERIALIZER": "pickle", # default: "msgpack"
}
Note: Pickle can execute arbitrary code on deserialization. Only use it if you trust all data in your cache.
Configure the compression threshold with COMPRESS_MIN_LEN in OPTIONS:
"OPTIONS": {
"COMPRESS_MIN_LEN": 2048, # compress values larger than 2KB
}
Async usage
You must use an ASGI server for async cache methods. For example, you can use granian:
granian --interface asgi --host 0.0.0.0 --port 8000 myproject.asgi:application
Sync methods (get, set, etc.) work in any context (ASGI or WSGI).
FAQ
Is this production-ready? Yes. It powers GlitchTip in production. The driver automatically reconnects after Valkey restarts and supports standalone, Sentinel, and Cluster topologies.
How is this different from django-valkey? django-vcache is opinionated — one serializer, one connection strategy, no knobs to turn. If you need maximum flexibility (custom serializers, connection pools, pluggable clients), use django-valkey. If you want something fast that just works, use this.
Does it work with Redis?
Yes. redis:// and rediss:// URLs work. Valkey and Redis are wire-compatible.
Contributing
Development Environment
This project uses Docker for development. To get started:
-
Clone the repository.
-
Build and start the services:
docker compose up -d --build
This will start a Valkey container and an app container with the Django sample project running on http://localhost:8000. The development server uses granian with auto-reload, so changes you make to the code will be reflected automatically.
Using Valkey Sentinel
To run the development environment with Valkey Sentinel enabled, use the override compose file:
docker compose -f compose.yml -f compose.sentinel.yml up -d --build
You will also need to configure your sample/settings.py to use the Sentinel URL. The recommended way is to set the VALKEY_URL environment variable before starting the services:
export VALKEY_URL="sentinel://localhost:26379/mymaster/1"
The application will then be available at http://localhost:8000.
Using Valkey Cluster
To use django-vcache with a Valkey Cluster, set the CLUSTER_MODE option to True in your cache configuration. The LOCATION should point to one of the cluster's nodes; the driver will automatically discover the rest of the cluster nodes.
CACHES = {
"default": {
"BACKEND": "django_vcache.backend.ValkeyCache",
"LOCATION": "valkey://your-cluster-node-1:6379/0",
"OPTIONS": {
"CLUSTER_MODE": True,
}
},
}
Note that distributed locking (via cache.lock() and cache.alock()) is not supported when CLUSTER_MODE is enabled. Attempting to use these methods will raise a NotImplementedError.
To run the development environment with Valkey Cluster enabled, use the override compose file and environment variables:
docker compose -f compose.yml -f compose.cluster.yml up -d --build \
-e VALKEY_URL='valkey://valkey-1:6379/0' \
-e VALKEY_CLUSTER_MODE='true'
The application will then be available at http://localhost:8000.
Running Tests
To run the test suite, execute the following command:
docker compose run --rm app bash -c "python sample/manage.py test"
Credits
Inspired by the excellent work of django-valkey, django-redis, valkey-glide, but re-architected for strict resource efficiency and modern async/sync hybrid stacks.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_vcache-2.1.0.tar.gz.
File metadata
- Download URL: django_vcache-2.1.0.tar.gz
- Upload date:
- Size: 102.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75f522aa61641c98e670eb18aa2d8ac9c954bc4f2ddc0c5eca8a9b97a2dc5fcc
|
|
| MD5 |
9d3f652fcf59c3dfb2aa20ef80e1ef0d
|
|
| BLAKE2b-256 |
86fbd3f63cb6520132598cca8cf1b09cc5718f0ba63c02063b6c2a0ae0c38e40
|
File details
Details for the file django_vcache-2.1.0-cp314-cp314-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: django_vcache-2.1.0-cp314-cp314-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.14, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38f2ac97966c0883cd37b7d007e4b14d93c646625cb51a3939d875bd8fed4bde
|
|
| MD5 |
534fd2d936b9f7c4deed36630b4e1d3b
|
|
| BLAKE2b-256 |
16d92f63e44d8d8bed905829bf1c87457117799e55623ebffc595a2fd13d5063
|
File details
Details for the file django_vcache-2.1.0-cp314-cp314-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: django_vcache-2.1.0-cp314-cp314-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.14, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e7435eb54d5c38d7be55898c13d821697fb6e58e86a3939c39e19387cfcdef7
|
|
| MD5 |
ddf3d46139a543959e4d312b62489da5
|
|
| BLAKE2b-256 |
d55fec7a55bd9402796b9d55e971c377c24dd0f4bb767947d26488a4302df05c
|
File details
Details for the file django_vcache-2.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: django_vcache-2.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.14, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b610cda986f9afc6393824b24a687a37250c9683b40cb1d4e7260011327ff31d
|
|
| MD5 |
ebfbc883307bb435b3ef5f5b57a462ab
|
|
| BLAKE2b-256 |
c5fc5f78dc2f3d5356ef8640a596c25748725b423b57b1b7a2be03bd284970b9
|
File details
Details for the file django_vcache-2.1.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: django_vcache-2.1.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.14, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44d0a08a601d508e463e8232fa2f7a4da328f773e085b95ddbfe27dd0dd4f92f
|
|
| MD5 |
55d524031944c066a85f54587e9f3aa9
|
|
| BLAKE2b-256 |
1edb95be754c7fd37ce31542da2bf062c3b12fab5ca5e34b8fca066220c4de93
|
File details
Details for the file django_vcache-2.1.0-cp313-cp313-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: django_vcache-2.1.0-cp313-cp313-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.13, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46ecaba421e6096d7d10467ffb148fe4115d1d8a23f5f09c029e81c86d010592
|
|
| MD5 |
6bf6423a5d216eaf630435757f76ac16
|
|
| BLAKE2b-256 |
4b7e0fc8cdf1184f7a56e560b2e82638a8a4bbeaff8486881812bb941291ede4
|
File details
Details for the file django_vcache-2.1.0-cp313-cp313-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: django_vcache-2.1.0-cp313-cp313-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.13, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb4f32df1a8a0884f1af28e8e4ce49c34e41b118a3ff25a87ccb045e28165b45
|
|
| MD5 |
734f71acd02dbf1d3312050b905962e0
|
|
| BLAKE2b-256 |
bcedf452c3c9f4352feb0a929b7e6c53177027a0fdd9f135cfed6576190292ff
|
File details
Details for the file django_vcache-2.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: django_vcache-2.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3e695072e67b63b8e1d8d71462788bdd47b37901ca0d0238d7201a4c2df00e5
|
|
| MD5 |
618b5dd56894f2075c488793cc202049
|
|
| BLAKE2b-256 |
06b1db5d77b848787cd803fb51fe07951afa4865ff2989404a36c4a918173020
|
File details
Details for the file django_vcache-2.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: django_vcache-2.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc5cfadd74b7896d2acae176de30ae09d7bfd3fd8dfb7c1bce3f06780c4455ee
|
|
| MD5 |
49dd530487bf7f66ebd4fc7a6e39c249
|
|
| BLAKE2b-256 |
7eb65fc92f456d3674f924e17a83a8c99c7eaa929c7e739f0cc848a8a2fa7fe8
|
File details
Details for the file django_vcache-2.1.0-cp312-cp312-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: django_vcache-2.1.0-cp312-cp312-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.12, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84589b769dafe639e5103e6a217e2f64fd88caa7672fdc9e3894aee79cef8469
|
|
| MD5 |
253c218af9a0bcdc1501df57de0f2112
|
|
| BLAKE2b-256 |
4e79961641e4bc20dfec685ccf3bfa2f79b39329b7a5b4640ebc8eab0edf329e
|
File details
Details for the file django_vcache-2.1.0-cp312-cp312-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: django_vcache-2.1.0-cp312-cp312-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.12, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45919253ed66153344813b2d0f1f621748ac09d5f0707b6784c4d2a7be52588f
|
|
| MD5 |
aa512109eceaa339e33ebd098a33456d
|
|
| BLAKE2b-256 |
3c38d3502a30e17b6769ad93658cd101cc4cf47185c8b3487674588600479c6c
|
File details
Details for the file django_vcache-2.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: django_vcache-2.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1b5f2ae91ad7dcfd39137f7deff9beed16d8a47261964ce275330fd0d5ab094
|
|
| MD5 |
19332d2f914ce4bd0c11abc78a64f29e
|
|
| BLAKE2b-256 |
049f3cfb48a7b3e2c8d3785e76e4e380a40aae6351786e1f2ce1fcd533ad42da
|
File details
Details for the file django_vcache-2.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: django_vcache-2.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac8ada90f878fc193776240af8b14623f652222ce4946ae588bdb7f5d86e8efa
|
|
| MD5 |
b3467d712bb61097fc5152862d35aabe
|
|
| BLAKE2b-256 |
0adc4da0b9ece62304201358df3e61532062cab9b19e141494af19c7a27a69d6
|