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.

Rotating credentials (AWS ElastiCache IAM auth)

For a cache that authenticates with a short-lived token instead of a fixed password, set credential_provider to a callable the driver consults and keeps current. ElastiCache IAM auth ships ready-made:

CACHES = {
    "default": {
        "BACKEND": "django_vcache.backend.ValkeyCache",
        "LOCATION": "valkeys://app-iam-user@my-cache-abc123.serverless.use1.cache.amazonaws.com:6379/0",
        "OPTIONS": {
            "credential_provider": "django_vcache.contrib.aws.elasticache_iam_token",
        },
    },
}

Install with pip install "django-vcache[aws]". The driver mints a fresh token before each one expires and re-authenticates every live connection, which also resets ElastiCache's 12-hour IAM connection limit. Any issuer works: a provider is a plain function returning a password (optionally with username and expires_at). See the configuration docs.

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.2.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.2.0
File Size Uploaded
django_vcache-3.2.0.tar.gz 87.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for django-vcache 3.2.0
File
django_vcache-3.2.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.2.0-cp314-cp314-musllinux_1_2_aarch64.whl CPython 3.14 CPython 3.14 Linux musl 1.2+ ARM64 Details
django_vcache-3.2.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.2.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.2.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.2.0-cp313-cp313-musllinux_1_2_aarch64.whl CPython 3.13 CPython 3.13 Linux musl 1.2+ ARM64 Details
django_vcache-3.2.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.2.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.2.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.2.0-cp312-cp312-musllinux_1_2_aarch64.whl CPython 3.12 CPython 3.12 Linux musl 1.2+ ARM64 Details
django_vcache-3.2.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.2.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: 29.9 MB

Release files / django_vcache-3.2.0.tar.gz

Download URL django_vcache-3.2.0.tar.gz
Size 87.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bde14278a279d82f18c9d46dc260c450816195ba12c32ed700b1f3f04d68652f
BLAKE2b-256 checksum
How to use checksums
69c309fe2a6d660337913bd84a107ca87e5b69ddae46340ca5eda2cc572ceaf8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.12 {"installer":{"name":"uv","version":"0.12.12","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.2.0-cp314-cp314-musllinux_1_2_x86_64.whl

Download URL django_vcache-3.2.0-cp314-cp314-musllinux_1_2_x86_64.whl
Size 2.5 MB
Tags CPython 3.14 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
9d3f3fb8c1ac95ccaaac122bfbb93c1b52c426597460aa82378f6560ba724caf
BLAKE2b-256 checksum
How to use checksums
30d9cb8e35883a7beb764f7a15e6b7931658837c824c72c90bfe2eed68f0e8c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.12 {"installer":{"name":"uv","version":"0.12.12","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.2.0-cp314-cp314-musllinux_1_2_aarch64.whl

Download URL django_vcache-3.2.0-cp314-cp314-musllinux_1_2_aarch64.whl
Size 2.4 MB
Tags CPython 3.14 Linux musl 1.2+ ARM64
SHA-256 checksum
How to use checksums
fe779584805c536d7d5f5a2fc47323f9bfe5d486eb48914d41f69ac21eab1850
BLAKE2b-256 checksum
How to use checksums
5889cc9148ce54f07e702a56ea38762298cca3c803818ce48857727236fe33ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.12 {"installer":{"name":"uv","version":"0.12.12","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.2.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL django_vcache-3.2.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.5 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
297a64643e41bc671b02c7d200ded6f39f868e22a2c60d4cb55322c15f5c5830
BLAKE2b-256 checksum
How to use checksums
014a42c94f7cff4ba9f0b90f5dec97d848e380fd9025a9de47c6732147030d37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.12 {"installer":{"name":"uv","version":"0.12.12","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.2.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL django_vcache-3.2.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.4 MB
Tags CPython 3.14 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
163044ef80decc1730f951d48bfa85b4b2cfdf9e75aba5bae0d616fed9ac6b7a
BLAKE2b-256 checksum
How to use checksums
3407a285141ac82f091e7788e42bd2d554d026dab898f32aaa51a868ea07f1a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.12 {"installer":{"name":"uv","version":"0.12.12","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.2.0-cp313-cp313-musllinux_1_2_x86_64.whl

Download URL django_vcache-3.2.0-cp313-cp313-musllinux_1_2_x86_64.whl
Size 2.5 MB
Tags CPython 3.13 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
8ea363e96c36e82c1c834247239bfd0574220bf3de0e7d7277f3c9cfcf5f5e42
BLAKE2b-256 checksum
How to use checksums
5bb22e90b11bd3578a8b46ea035b81e3a468723b0cc3a844263f4db629827a0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.12 {"installer":{"name":"uv","version":"0.12.12","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.2.0-cp313-cp313-musllinux_1_2_aarch64.whl

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

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

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

Download URL django_vcache-3.2.0-cp312-cp312-musllinux_1_2_x86_64.whl
Size 2.5 MB
Tags CPython 3.12 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
fc096c86124efb5bdcdfce46ed51b05c9ba1b5fc409adc166eb1c8a495a4c9cf
BLAKE2b-256 checksum
How to use checksums
992f75360ea76452294b9be6c229d87058ba85ed1c3ccf1dc4f1063a3f75f796
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.12 {"installer":{"name":"uv","version":"0.12.12","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.2.0-cp312-cp312-musllinux_1_2_aarch64.whl

Download URL django_vcache-3.2.0-cp312-cp312-musllinux_1_2_aarch64.whl
Size 2.4 MB
Tags CPython 3.12 Linux musl 1.2+ ARM64
SHA-256 checksum
How to use checksums
1a9273b159138f7a681e21982b12d7b0e8bd385e955fabc577732465747b8f32
BLAKE2b-256 checksum
How to use checksums
e5c9eee40e568fe811ff3d91c028c8ea2e4be77403c6319f306aa67b94cd59cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.12 {"installer":{"name":"uv","version":"0.12.12","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.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

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

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

This release

3.2.0 This release

13 release files

3.1.1

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