Skip to main content

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_async thread-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.zstd on 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:

  1. Clone the repository.

  2. 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.

Metadata

Release files for django-vcache 3.0.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-vcache 3.0.0
File Size Uploaded
django_vcache-3.0.0.tar.gz 56.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for django-vcache 3.0.0
File
django_vcache-3.0.0-cp314-cp314-musllinux_1_2_x86_64.whl CPython 3.14 CPython 3.14 Linux musl 1.2+ x86-64 Details
django_vcache-3.0.0-cp314-cp314-musllinux_1_2_aarch64.whl CPython 3.14 CPython 3.14 Linux musl 1.2+ ARM64 Details
django_vcache-3.0.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64 Details
django_vcache-3.0.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ ARM64 Details
django_vcache-3.0.0-cp313-cp313-musllinux_1_2_x86_64.whl CPython 3.13 CPython 3.13 Linux musl 1.2+ x86-64 Details
django_vcache-3.0.0-cp313-cp313-musllinux_1_2_aarch64.whl CPython 3.13 CPython 3.13 Linux musl 1.2+ ARM64 Details
django_vcache-3.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
django_vcache-3.0.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ ARM64 Details
django_vcache-3.0.0-cp312-cp312-musllinux_1_2_x86_64.whl CPython 3.12 CPython 3.12 Linux musl 1.2+ x86-64 Details
django_vcache-3.0.0-cp312-cp312-musllinux_1_2_aarch64.whl CPython 3.12 CPython 3.12 Linux musl 1.2+ ARM64 Details
django_vcache-3.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
django_vcache-3.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ ARM64 Details

Total release size: 27.5 MB

Release files / django_vcache-3.0.0.tar.gz

Download URL django_vcache-3.0.0.tar.gz
Size 56.5 kB
Tags Source
SHA-256 checksum
How to use checksums
98e1e05eda63a790570d75463a438fdccc99b981743f4aa8b9be051f1b3f22e5
BLAKE2b-256 checksum
How to use checksums
6041d12be2d30b0bf7154561fc158ff5f465cfe35d3ea1b98d49b3de35f91089
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}

Release files / django_vcache-3.0.0-cp314-cp314-musllinux_1_2_x86_64.whl

Download URL django_vcache-3.0.0-cp314-cp314-musllinux_1_2_x86_64.whl
Size 2.4 MB
Tags CPython 3.14 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
6481c1341fc0beb817e90fcfa7f789543f51af63ea6ab75e8ae26515d39b41da
BLAKE2b-256 checksum
How to use checksums
2e95d0a30dfcca74bcd962c70832b72d8a2a423b24f8d4c324548dc9a9ab0a02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}

Release files / django_vcache-3.0.0-cp314-cp314-musllinux_1_2_aarch64.whl

Download URL django_vcache-3.0.0-cp314-cp314-musllinux_1_2_aarch64.whl
Size 2.2 MB
Tags CPython 3.14 Linux musl 1.2+ ARM64
SHA-256 checksum
How to use checksums
5f451206ef07dafbfc02149264d3c884d0d35b4868a8c1e90d0a140c12a29fa4
BLAKE2b-256 checksum
How to use checksums
de3c78b9c7412d08028b8fc4ce95be84c6e05b0a3fb1c14a8b50c6e5614dc9a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}

Release files / django_vcache-3.0.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL django_vcache-3.0.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.3 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
af521d795d5d468386f25bff185ca6153e0fd9542b220b151085b6981f7cb78e
BLAKE2b-256 checksum
How to use checksums
5bb556dddfaa32b72e8d7a9f1e97dee6b0653a02d829ed2993d08baed54098b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}

Release files / django_vcache-3.0.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL django_vcache-3.0.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.2 MB
Tags CPython 3.14 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
80217629805cd2cda8ac23bb6b02135105ab12c8cff4ce1705e39bcf8f14973e
BLAKE2b-256 checksum
How to use checksums
0b9fb76d2c1e5972a330149f5b5fa460397579f16afb0de59c947f81d5ae450d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}

Release files / django_vcache-3.0.0-cp313-cp313-musllinux_1_2_x86_64.whl

Download URL django_vcache-3.0.0-cp313-cp313-musllinux_1_2_x86_64.whl
Size 2.4 MB
Tags CPython 3.13 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
5a555a2be787f22926fe9a74baccc3c52d116637d91d7168e275f88d2bf936d0
BLAKE2b-256 checksum
How to use checksums
596914ffb2cd3d079a65715b2b378f07a000996f701c3329f04105136f22795d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}

Release files / django_vcache-3.0.0-cp313-cp313-musllinux_1_2_aarch64.whl

Download URL django_vcache-3.0.0-cp313-cp313-musllinux_1_2_aarch64.whl
Size 2.2 MB
Tags CPython 3.13 Linux musl 1.2+ ARM64
SHA-256 checksum
How to use checksums
db3c7c3cd0d220c6358d362bcb5cfd4f57f2c6a9d059a07d4ce7e979b67fd241
BLAKE2b-256 checksum
How to use checksums
86c1b3c725ca3795d3ed9eaa779de3ebee22a9f8e5e9d7a58272119a9160dccb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}

Release files / django_vcache-3.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL django_vcache-3.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.3 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
911af2311f8384412882d6bfc89e9584348ccb50c343f1e8ee61001d3c9fc79d
BLAKE2b-256 checksum
How to use checksums
a05196448c9f2db6be1f37341e04263e4a2a1e719d342727f4207dafdd1a48f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}

Release files / django_vcache-3.0.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL django_vcache-3.0.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.2 MB
Tags CPython 3.13 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
1e2a6066f3fa36005077ca55b459828ed99d70403126b3166e4f0f3dd5f348e4
BLAKE2b-256 checksum
How to use checksums
d4d3935ff24b847ac8e50a59ada5eb935e397c5bd20f72cc94edbbe3beaf778f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}

Release files / django_vcache-3.0.0-cp312-cp312-musllinux_1_2_x86_64.whl

Download URL django_vcache-3.0.0-cp312-cp312-musllinux_1_2_x86_64.whl
Size 2.4 MB
Tags CPython 3.12 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
826212373254a76569766ab26864b654ce8c1e361beb3a1fe145b6870f0364f1
BLAKE2b-256 checksum
How to use checksums
866f2c20dc1bd806a318888050e1da7aecbf425cc3d0521c56d45501265073dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}

Release files / django_vcache-3.0.0-cp312-cp312-musllinux_1_2_aarch64.whl

Download URL django_vcache-3.0.0-cp312-cp312-musllinux_1_2_aarch64.whl
Size 2.2 MB
Tags CPython 3.12 Linux musl 1.2+ ARM64
SHA-256 checksum
How to use checksums
500c2de70946ee812993085d664e8436d462a895d58205750bb83dda2cd2f13e
BLAKE2b-256 checksum
How to use checksums
d9f32007734586aa5b91433095b504dd2944b6c145d214ba0cb7507c2d8697ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}

Release files / django_vcache-3.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL django_vcache-3.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.3 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
9fb9741d969b5967a4c23345ebf9c94f9d07d3046af15512b7d135c6a02a294b
BLAKE2b-256 checksum
How to use checksums
c2b989a633b2926560797f3a15c347a4e2a1bdeb61d9c38867f6b27c4ad1537a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}

Release files / django_vcache-3.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL django_vcache-3.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.2 MB
Tags CPython 3.12 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
236a45e1d1e5f03b9ba03c275be5fb5156c062d2161e6eeb9e4931b10fe9edce
BLAKE2b-256 checksum
How to use checksums
5353ef7ed8f5a4cf533df6974b7aed3fe007d01b45c988772dccdf8a6a5c2b02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}

Release history Release notifications | RSS feed

3.2.0

13 release files

3.1.1

13 release files

3.1.0

13 release files

This release

3.0.0 This release

13 release files

2.3.0

13 release files

2.1.0

13 release files

2.0.9

13 release files

2.0.8

13 release files

2.0.7

13 release files

2.0.6

13 release files

2.0.5

13 release files

2.0.4

13 release files

2.0.3

13 release files

2.0.2

13 release files

2.0.1

13 release files

2.0.0

13 release files

1.0.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

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