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).
  • Two composite backends: StreamCache (cross-pod stream-synchronized in-memory cache) and TrackingCache (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+ (free-threaded supported)
  • Django 6.0+
  • valkey-py 6.1+ or redis-py 6.0+
  • Valkey 7.2+ or Redis 6.0+ on the server (the admin's compare-and-swap edits use SET ... KEEPTTL, which lands in Redis 6.0)
  • Hash field expiration needs Valkey 9.0+ or Redis 7.4+, and hsetex/hgetex 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, 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.9.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.9.0
File Size Uploaded
django_cachex-0.9.0.tar.gz 220.0 kB Details

Built distribution (wheel)

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

Total release size: 473.3 kB

Release files / django_cachex-0.9.0.tar.gz

Download URL django_cachex-0.9.0.tar.gz
Size 220.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a4d3bf940521874b1e8d68d05971eefa86a9a73edc8591371fd789870f507cef
BLAKE2b-256 checksum
How to use checksums
960a2c8585ed21c808f15626ccec4327df199d43d5b4041673d4f2e9242c65e2
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 10, 2026.

Transparency log

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

Download URL django_cachex-0.9.0-py3-none-any.whl
Size 253.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a965c23ee62412d6c9c56ef8043bda1ec690858ef29b07daef00c2e65d85b5c4
BLAKE2b-256 checksum
How to use checksums
7f4e4f8ee8c217faefba0badf7d262ca07c8ee09d84ba364d295c7621418a569
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 10, 2026.

Transparency log

Release history Release notifications | RSS feed

0.11.1

2 release files

0.11.0

2 release files

0.10.0

2 release files

This release

0.9.0 This release

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