Skip to main content

django-cachex

PyPI version Python versions CI

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 both Valkey and Redis, default and Sentinel and Cluster.
  • Sync and async support sharing one configuration: every cache exposes both get() and aget(), backed by the same alias.
  • Hash, list, set, sorted set, and stream operations on the cache object.
  • TTL and pattern helpers (ttl(), expire(), keys(), delete_pattern()).
  • Distributed locks: cache.lock().
  • Weighted semaphores: cache.semaphore() for budget-based concurrency gating (counting and weighted, in-process and distributed).
  • Lua scripting with automatic key prefixing and value encoding/decoding.
  • Pluggable serializers (Pickle, JSON, MsgPack, ormsgpack, orjson) and compressors (Zlib, Gzip, LZ4, LZMA, Zstandard), each with fallback chains for safe migrations.
  • Cache stampede prevention (TTL-based XFetch).
  • TrackingCache, a local read cache over a Redis/Valkey alias, invalidated by the server's CLIENT TRACKING or bounded by a local TTL.
  • Django LocMemCache and DatabaseCache extensions with the hash, list, set and sorted set ops, ttl()/expire()/persist(), key patterns, and admin support (no streams, locks, pipelines or Lua).
  • Optional valkey-glide adapter: Valkey's official Rust-cored client, exposed as ValkeyGlideCache. Experimental.
  • Django admin UI for browsing keys, inspecting values, editing, and flushing. See below.

Cache Admin

Add django_cachex.admin to your INSTALLED_APPS to enable the cache admin interface:

INSTALLED_APPS = [
    # ...
    "django_cachex.admin",
]

Browse all configured caches, search and filter keys by type, and manage values directly:

Cache list Key list Key detail

Features:

  • Browse all configured cache backends (Valkey, Redis, LocMemCache, DatabaseCache, and more)
  • Search keys with wildcard patterns (user:*, *:session)
  • Filter by key type (string, list, set, hash, zset, stream)
  • View and edit values with type-specific operations
  • Inspect and modify TTL
  • View server info and memory statistics
  • Flush 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: hiredis and libvalkey are C extensions without free-threading support, so importing either on 3.14t re-enables the GIL with a RuntimeWarning. Run with PYTHON_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 6.0 to 8.x (redis>=6,<9)
  • Valkey 7.2+ or Redis 6.2+ on the server. set(get=True) and the immediate-expiry conditional writes (add() and set(nx=/xx=/get=) with timeout=0) send SET ... GET and SET ... PXAT, both Redis 6.2 commands; set(nx=True, get=True) and expiretime() need Redis 7.0+
  • Hash field expiration needs Valkey 9.0+ or Redis 7.4+, and hsetex/hgetex Valkey 9.0+ or Redis 8.0+; older servers raise NotSupportedError for those methods

The valkey-glide adapter is optional and experimental: interfaces and behavior may still change, and it has seen less production testing than the redis-py/valkey-py paths. Install with the valkey-glide extra (pip install django-cachex[valkey-glide]) to enable ValkeyGlideCache; it pulls in valkey-glide-sync and valkey-glide (2.5 to 2.x), the official Rust-cored Valkey client. cp314 GIL only; no free-threaded wheels yet. Cluster is supported via ValkeyGlideClusterCache; Sentinel is not currently exposed (valkey-glide itself does not ship a Sentinel client).

Acknowledgments

This project started from django-redis and Django's official Redis cache backend. Some serializer and compressor utility code is derived from django-redis, licensed under BSD-3-Clause. The admin UI was inspired by django-redisboard.

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

Metadata

Release files for django-cachex 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-cachex 0.10.0
File Size Uploaded
django_cachex-0.10.0.tar.gz 222.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-cachex 0.10.0
File Interpreter ABI Platform
django_cachex-0.10.0-py3-none-any.whl Python 3 none any Details

Total release size: 478.4 kB

Release files / django_cachex-0.10.0.tar.gz

Download URL django_cachex-0.10.0.tar.gz
Size 222.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d67a815f8cbd0f70f5ba2146c6d8ac426744b09ddac9dd1cb3526031ecc3df7a
BLAKE2b-256 checksum
How to use checksums
30eb7d6c42f02736a71bc68b59fe38dea815764d89d7a1db87a0d47763c02f3c
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 17, 2026.

Transparency log

Release files / django_cachex-0.10.0-py3-none-any.whl

Download URL django_cachex-0.10.0-py3-none-any.whl
Size 255.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f3c4e1d11830b10d2ab2d5fbf4f3fc5f743b586a7cab9aa5d7f86079cb64295
BLAKE2b-256 checksum
How to use checksums
bd166637be5cf9626b95d958040535a2b37b8a627ea67444918112e223648989
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 17, 2026.

Transparency log

Release history Release notifications | RSS feed

0.11.1

2 release files

0.11.0

2 release files

This release

0.10.0 This release

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page