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

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.1.1
File Size Uploaded
django_vcache-3.1.1.tar.gz 57.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for django-vcache 3.1.1
File
django_vcache-3.1.1-cp314-cp314-musllinux_1_2_x86_64.whl CPython 3.14 CPython 3.14 Linux musl 1.2+ x86-64 Details
django_vcache-3.1.1-cp314-cp314-musllinux_1_2_aarch64.whl CPython 3.14 CPython 3.14 Linux musl 1.2+ ARM64 Details
django_vcache-3.1.1-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.1.1-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ ARM64 Details
django_vcache-3.1.1-cp313-cp313-musllinux_1_2_x86_64.whl CPython 3.13 CPython 3.13 Linux musl 1.2+ x86-64 Details
django_vcache-3.1.1-cp313-cp313-musllinux_1_2_aarch64.whl CPython 3.13 CPython 3.13 Linux musl 1.2+ ARM64 Details
django_vcache-3.1.1-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.1.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ ARM64 Details
django_vcache-3.1.1-cp312-cp312-musllinux_1_2_x86_64.whl CPython 3.12 CPython 3.12 Linux musl 1.2+ x86-64 Details
django_vcache-3.1.1-cp312-cp312-musllinux_1_2_aarch64.whl CPython 3.12 CPython 3.12 Linux musl 1.2+ ARM64 Details
django_vcache-3.1.1-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.1.1-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.7 MB

Release files / django_vcache-3.1.1.tar.gz

Download URL django_vcache-3.1.1.tar.gz
Size 57.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ab50a42edc63e0a639b9a6e2b4b9508ca98a430bd4586e7b65fca6079f334bc1
BLAKE2b-256 checksum
How to use checksums
2578370b7da4cc55753cf9d2edd5b4807b20115f6fc6d6c89fac9629e8fea5c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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.1.1-cp314-cp314-musllinux_1_2_x86_64.whl

Download URL django_vcache-3.1.1-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
0e2218884e60d1fa237b7bb29a47c5e76d37ee3aa8abacacffc3b77b362ba197
BLAKE2b-256 checksum
How to use checksums
5eed377868094f718a35bd07d8e265f72224c7b1fd16d78da7997776b90140a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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.1.1-cp314-cp314-musllinux_1_2_aarch64.whl

Download URL django_vcache-3.1.1-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
e401d026b5fb38c1fe652f75d9a00559deaa432cdfef180cd472aa8d6f5012d3
BLAKE2b-256 checksum
How to use checksums
f0aa707d1407ebf41edc566fb040adb3c4bfd38ad0db299c10cec72c315ecb75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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.1.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL django_vcache-3.1.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.4 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
5c7a827b11814bcc4a27f467c312c992c4afa6aedaca943f4c97a3bc861efb8b
BLAKE2b-256 checksum
How to use checksums
658bde522efc5c059aa52b792c4bc81e59a05677ed63e47e5b934cc4c40b8c76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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.1.1-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL django_vcache-3.1.1-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
49dc3717f3d1c8e6566e5badfa26546c06345ea490f7d822bb63e7ea71b0206f
BLAKE2b-256 checksum
How to use checksums
34943bbf3d21d187011c79dfb5942527fca2992e837bcc31a7add775916ab0f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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.1.1-cp313-cp313-musllinux_1_2_x86_64.whl

Download URL django_vcache-3.1.1-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
3db7fe13d4cc7ab0b911b9f72827afbcda15d54d7731776dd689261441de7dd2
BLAKE2b-256 checksum
How to use checksums
2669c9b732e6473d3c18c40ae1dab4f74d737e6abfe503ac572cca6a8677d310
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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.1.1-cp313-cp313-musllinux_1_2_aarch64.whl

Download URL django_vcache-3.1.1-cp313-cp313-musllinux_1_2_aarch64.whl
Size 2.3 MB
Tags CPython 3.13 Linux musl 1.2+ ARM64
SHA-256 checksum
How to use checksums
0042d5b47fda3db1cbf92b4076844f1b9be53527471aae0efc7a3d28f3c48b6e
BLAKE2b-256 checksum
How to use checksums
b80b757a29dc0c36ffa928722de2870e2ffab87ac4de4ebf824ddc8cb4230f9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL django_vcache-3.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.4 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
dda63add3ac7a97da99497b36b85d7ce14af3521ba93d0071158d13f9f671774
BLAKE2b-256 checksum
How to use checksums
c5be7c102e71ab21f3bbaac2791eb168cb95fab67f9e1704fcafad54fe14e022
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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.1.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL django_vcache-3.1.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.3 MB
Tags CPython 3.13 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
495ae28686dfc531b88dc73ffc9e41e28cdaca2110314fa136614ac99f22829c
BLAKE2b-256 checksum
How to use checksums
b04f6283f22c3cc6a7f2406f23f2079c58cdbcfcea0ac07f195167869b53efbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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.1.1-cp312-cp312-musllinux_1_2_x86_64.whl

Download URL django_vcache-3.1.1-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
6fe3cae524125c2366900dd33edc6686b32037f334fe8f0ea9cc1f23ed8b7f31
BLAKE2b-256 checksum
How to use checksums
82ddebca85e5cc60dde3ca4fc799975c0cda0b0730e5444ad57a414e58cd0f92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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.1.1-cp312-cp312-musllinux_1_2_aarch64.whl

Download URL django_vcache-3.1.1-cp312-cp312-musllinux_1_2_aarch64.whl
Size 2.3 MB
Tags CPython 3.12 Linux musl 1.2+ ARM64
SHA-256 checksum
How to use checksums
6d7bc42ed949c08d624046503232e3cdd17c800197515980997ece81eab7ec7e
BLAKE2b-256 checksum
How to use checksums
108778b49af104f63add7b6236108ab4536437a867410ce14976ad96c17be08e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL django_vcache-3.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.4 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
889c5705f8413b1e2651db2eff116e02dee713dde1d8a06a04feed43d5cc1b27
BLAKE2b-256 checksum
How to use checksums
bef1969cb42ed34580f8ad27f70d25bba6180579e0db739ff926628b1c247cc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

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

This release

3.1.1 This release

13 release files

3.1.0

13 release files

3.0.0

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