django-cachex
Valkey and Redis cache backend for Django, with a Django admin UI for cache inspection.
Installation
pip install django-cachex[valkey-py]
Quick Start
CACHES = {
"default": {
"BACKEND": "django_cachex.cache.ValkeyCache",
"LOCATION": "valkey://127.0.0.1:6379/1",
}
}
What's in the box
- One package for Valkey and Redis, standalone, Sentinel and Cluster.
- Sync and async methods on every cache, such as
get()andaget(), from one alias and one configuration. - Hash, list, set, sorted set and stream operations on the cache object.
- TTL and pattern helpers (
ttl(),expire(),keys(),delete_pattern()). - Distributed locks with
cache.lock(). - Counting and weighted semaphores with
cache.semaphore(), in-process or distributed, to cap concurrent work at a budget. - Lua scripting with
eval_script(), with optional hooks for key prefixing and value encoding and decoding. - Pluggable serializers (Pickle, JSON, MsgPack, ormsgpack, orjson) and compressors (Zlib, Gzip, LZ4, LZMA, Zstandard), each with a fallback chain to migrate between formats.
- Cache stampede prevention (TTL-based XFetch).
TrackingCache, a local read cache over a Redis or Valkey alias, invalidated by the server'sCLIENT TRACKINGor bounded by a local TTL.- An opt-in ORM cache,
django_cachex.orm, derived from django-cachalot. It caches ORM query results per table and invalidates them on every write. Write leases keep a write from leaving a stale result behind. LocMemCacheandDatabaseCacheextensions with the hash, list, set and sorted set operations,ttl()/expire()/persist(), key patterns and admin support. They have no streams, locks, pipelines or Lua.- An experimental
ValkeyGlideCachebackend onvalkey-glide, Valkey's official client with a Rust core. - A Django admin UI to browse keys, inspect and edit values, and flush caches.
Cache Admin
Add django_cachex.admin to INSTALLED_APPS to enable the cache admin:
INSTALLED_APPS = [
# ...
"django_cachex.admin",
]
The admin lists every configured cache (Valkey, Redis, LocMemCache, DatabaseCache and others).
The key browser searches keys with wildcard patterns such as user:* or *:session.
It filters keys by type: string, list, set, hash, zset or stream.
The admin also edits values with type-specific operations, reads and changes TTLs, shows server info and memory statistics, and flushes caches.
Documentation
Full documentation at oliverhaas.github.io/django-cachex
Requirements
- Python 3.14+. The free-threaded build (3.14t) is supported, with one
caveat:
hiredisandlibvalkeyare C extensions without free-threading support, so importing either on 3.14t re-enables the GIL with aRuntimeWarning. Run withPYTHON_GIL=0(or-Xgil=0) to keep it disabled; that is how the CI 3.14t job runs the suite. - Django 6.0 to 6.x (
Django>=6,<7) - valkey-py 6.1 to 6.x (
valkey>=6.1,<7) or redis-py 7.2 to 8.x (redis>=7.2,<9) - Valkey 7.2+ or Redis 6.2+ on the server.
set(get=True)and the immediate-expiry conditional writes (add()andset(nx=/xx=/get=)withtimeout=0) sendSET ... GETandSET ... PXAT, both Redis 6.2 commands.set(nx=True, get=True)andexpiretime()need Redis 7.0+ - Hash field expiration needs Valkey 9.0+ or Redis 7.4+, and
hsetex/hgetexValkey 9.0+ or Redis 8.0+. Older servers raiseNotSupportedErrorfor those methods
The valkey-glide adapter is optional and experimental. Its interfaces and
behavior can change, and it has less production testing than the redis-py
and valkey-py backends. The valkey-glide extra
(pip install django-cachex[valkey-glide]) enables ValkeyGlideCache and
installs valkey-glide-sync and valkey-glide (2.5 to 2.x), Valkey's
official client with a Rust core. The adapter needs the cp314 GIL build,
because valkey-glide publishes no free-threaded wheels.
ValkeyGlideClusterCache supports Cluster. The adapter has no Sentinel
backend, because valkey-glide does not ship a Sentinel client.
Acknowledgments
This project started from django-redis and Django's official Redis cache backend. Some serializer, compressor and exception code is derived from django-redis, licensed under BSD-3-Clause. The admin UI was inspired by django-redisboard. The ORM cache (django_cachex.orm) is derived from django-cachalot 2.9.1 by Bertrand Bordage, licensed under BSD-3-Clause.
The ASGI benchmark follows the shape of django-vcache's bench_compare.py (MIT, by David Burke / GlitchTip), so the numbers are directly comparable.
I also want to mention django-valkey and dj-cache-panel, which I never really used, but are newer and interesting efforts of similar goals as this package has.
License
MIT, see LICENSE, except for two parts under BSD-3-Clause
(the package metadata declares MIT AND BSD-3-Clause):
- The ORM cache,
django_cachex/orm/, derived from django-cachalot. See django_cachex/orm/LICENSE. - Parts of
django_cachex/serializers/,django_cachex/compressors/anddjango_cachex/exceptions.py, derived from django-redis (Copyright (c) 2011-2016 Andrey Antukh). Each derived file says so in its header. See LICENSE.django-redis.
Metadata
Release files for django-cachex 0.11.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_cachex-0.11.0.tar.gz | 248.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_cachex-0.11.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 537.4 kB
Release files / django_cachex-0.11.0.tar.gz
| Download URL | django_cachex-0.11.0.tar.gz |
|---|---|
| Size | 248.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
db1df80eb1a692fe62ae0712b7cbdb036e0da876384763b61c09ea8afa84d02c
|
|
BLAKE2b-256 checksum How to use checksums |
bd0cf27c6bf0b6483bcd09e3c4afd1f1fd5a87ffcab8cc265069b9c7b162bcca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.
Transparency logRelease files / django_cachex-0.11.0-py3-none-any.whl
| Download URL | django_cachex-0.11.0-py3-none-any.whl |
|---|---|
| Size | 289.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b0932eddf25b2b3df1aab95ac0de4946f188f0c339df4bb14733963c569e2cda
|
|
BLAKE2b-256 checksum How to use checksums |
7b8ab4bd9f95b6821df7767581afa6734aefe0ef87fb42c990f000f3f3e7afa0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.
Transparency log