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.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.1.0
File Size Uploaded
django_vcache-3.1.0.tar.gz 57.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for django-vcache 3.1.0
File
django_vcache-3.1.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.1.0-cp314-cp314-musllinux_1_2_aarch64.whl CPython 3.14 CPython 3.14 Linux musl 1.2+ ARM64 Details
django_vcache-3.1.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.1.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.1.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.1.0-cp313-cp313-musllinux_1_2_aarch64.whl CPython 3.13 CPython 3.13 Linux musl 1.2+ ARM64 Details
django_vcache-3.1.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.1.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.1.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.1.0-cp312-cp312-musllinux_1_2_aarch64.whl CPython 3.12 CPython 3.12 Linux musl 1.2+ ARM64 Details
django_vcache-3.1.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.1.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.6 MB

Release files / django_vcache-3.1.0.tar.gz

Download URL django_vcache-3.1.0.tar.gz
Size 57.3 kB
Tags Source
SHA-256 checksum
How to use checksums
56284fc86ba85461cc3a51fdfa30290bb1d55d03072574bc670a089f6b2bd576
BLAKE2b-256 checksum
How to use checksums
99416eca00f4575028d3592cd9c54be316d6e5caa16ce43b385ce33124b32be3
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.1.0-cp314-cp314-musllinux_1_2_x86_64.whl

Download URL django_vcache-3.1.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
5646790f06adde3958bbbb28e5e9cff20860b943a74302733365b0a000be69fa
BLAKE2b-256 checksum
How to use checksums
738d64f7a8fa694c90b865f996f67473647aa76c262ee00bce4a93890ecd2a79
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.1.0-cp314-cp314-musllinux_1_2_aarch64.whl

Download URL django_vcache-3.1.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
1c747b025cfb7c17f3729561773b7548e55c049f0d803451ec8b24c1573f5f23
BLAKE2b-256 checksum
How to use checksums
e902badcaa2a862f6ab5610565c0fc211f8476113587f3e8794fd4993e328613
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.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL django_vcache-3.1.0-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
d480125bb24ca40ef7cd34e84d1adf12c90d2ec007285ffc42e9b03863931f41
BLAKE2b-256 checksum
How to use checksums
69061becd75cfb34a7f423610e2b224a8ae8d9f4760cda35832caf0d337d2113
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.1.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL django_vcache-3.1.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
2738c05f8c289701efb77b5a35e560ae0cb8de55ac6174a3e9470cd05f3cee41
BLAKE2b-256 checksum
How to use checksums
5c16c54d89086252ad2886f15ad57741ebbc88111544ad58a7c1cd9aff9519bf
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.1.0-cp313-cp313-musllinux_1_2_x86_64.whl

Download URL django_vcache-3.1.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
2026a2b256cca65a8b336195b0e14c607f99e9197554c0fa5c5734238b07e1af
BLAKE2b-256 checksum
How to use checksums
ebe7efbeb42847367df38dd1414c1697f3949f2438d16d377c55c8fbc17af81c
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.1.0-cp313-cp313-musllinux_1_2_aarch64.whl

Download URL django_vcache-3.1.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
d95960dd472af7e09962c62f79be8d81492d741889508f5174d06607dc61005c
BLAKE2b-256 checksum
How to use checksums
6b6576a297636d324bda4e4bfe7e1710c56bc07dc1df132ce83c31d23eb8fe12
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.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL django_vcache-3.1.0-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
b99e83fc2b697a2f7be96de67ddf4aadc864a3a2400eff3e49dfda8ba88de14d
BLAKE2b-256 checksum
How to use checksums
db0f8895a503dc83dc6920b6cf3e5005a63984a9c8d8379c01310f423ac48f41
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.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL django_vcache-3.1.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
624714458f19d36c78a5e786a2277a2c9e1678378551bdc26158511dc1680e25
BLAKE2b-256 checksum
How to use checksums
1ae2e0b2d21732c3d67a7f5922653e2d100ef02c21750a5e89df37dc62c8f83b
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.1.0-cp312-cp312-musllinux_1_2_x86_64.whl

Download URL django_vcache-3.1.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
3f0bb9f30eccc1a4824165583f21262185040e6b9f4c1fc390067b4d7bc9f013
BLAKE2b-256 checksum
How to use checksums
428652923e1fb6711404f3878825fcd714a64bc407d7191e3d72c55d03e80365
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.1.0-cp312-cp312-musllinux_1_2_aarch64.whl

Download URL django_vcache-3.1.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
9b4fd3d72475c1e1124b259520a56f203882ab8d73890f874f864b694ef1d8d6
BLAKE2b-256 checksum
How to use checksums
c8ad3ee0936e18ddf99b5a6f3173da165cc5b0078a237ab7c5ef9001c7b96aeb
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.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL django_vcache-3.1.0-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
56b69911128849d76a34aaecfe0ffd084473a85b606bd2c59e1c9d81742f134d
BLAKE2b-256 checksum
How to use checksums
fa3efa8a9148c8dde30d112371e906addc7fb048a402817e965503309332c4aa
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.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL django_vcache-3.1.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
b8ad66033843aa76da5e8a47739d6b82f1775d346b0d93410abc607a72740233
BLAKE2b-256 checksum
How to use checksums
36284ab224a60da415f3f75cf74f3f34a16979f839a29227ed58f074cf171183
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

This release

3.1.0 This release

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