Cache that invalidates when your data changes, not when a timer expires. Rust-powered semantic invalidation for Python.
Project description
Zoocache is a high-performance caching library with a Rust core, designed for applications where data consistency and read performance are critical.
✨ Key Features
- 🚀 Rust-Powered Performance: Core logic implemented in Rust for ultra-low latency and safe concurrency.
- 🧠 Semantic Invalidation: Use a
PrefixTriefor hierarchical invalidation. Clear "user:*" to invalidate all keys related to a specific user instantly. - 🛡️ Causal Consistency: Built-in support for Hybrid Logical Clocks (HLC) ensures consistency even in distributed systems.
- ⚡ Anti-Avalanche (SingleFlight): Protects your backend from "thundering herd" effects by coalescing concurrent identical requests.
- 📦 Smart Serialization: Transparently handles MsgPack and LZ4 compression for maximum throughput and minimum storage.
- 🔄 Self-Healing Distributed Cache: Automatic synchronization via Redis Bus with robust error recovery.
- 🛡️ Hardened Safety: Strict tag validation and mutex-poisoning protection to ensure zero-crash operations.
- 📊 Observability & Telemetry: Built-in support for Logs, Prometheus, and OpenTelemetry to monitor cache performance.
🚀 Performance
Zoocache is continuously benchmarked to ensure zero performance regressions. We track micro-latency, scaling with dependencies, and storage overhead.
Performance Context
The benchmark results reflect ZooCache's specific architectural choices:
- Rust Core: Implementing the core logic in Rust reduces the processing time spent on internal cache management and synchronization compared to pure Python implementations.
- Trie-based Invalidation: Instead of matching and deleting individual keys, ZooCache uses a
PrefixTrieto manage dependencies. Invalidation is performed by updating versions in the trie, which remains efficient even as the number of cached items grows. - Pub/Sub Bus: Using Redis Pub/Sub for the invalidation bus enables low-latency propagation of invalidation signals across multiple nodes, typically completing in under 1ms.
Note: Benchmark scale: 5,000 operations. Redis is running on localhost (loopback) to eliminate network latency interference and focus on internal engine overhead. ZooCache maintains O(1) tagging overhead and scales linearly. Latency values represent the end-to-end operation time including storage overhead.
Optional CLI & TUI
Zoocache includes an optional CLI for real-time monitoring and cache management. It can be installed using the cli extra:
uv add "zoocache[cli]"
⚖️ Comparison
| Feature | 🐾 Zoocache | 🔴 Redis (Raw) | 🐶 Dogpile | diskcache |
|---|---|---|---|---|
| Invalidation | 🧠 Semantic (Trie) | 🔧 Manual | 🔧 Manual | ⏳ TTL |
| Consistency | 🛡️ Causal (HLC) | ❌ Eventual | ❌ No | ❌ No |
| Anti-Avalanche | ✅ Native | ❌ No | ✅ Yes (Locks) | ❌ No |
| Performance | 🚀 Very High | 🏎️ High | 🐢 Medium | 🐢 Medium |
⚡ Quick Start
Installation
Using uv (recommended):
uv add zoocache
Using pip:
pip install zoocache
Simple Usage
from zoocache import cacheable, invalidate
@cacheable(deps=lambda user_id: [f"user:{user_id}"])
def get_user(user_id: int):
return db.fetch_user(user_id)
def update_user(user_id: int, data: dict):
db.save(user_id, data)
invalidate(f"user:{user_id}") # All cached 'get_user' calls for this ID die instantly
Complex Dependencies
from zoocache import cacheable, add_deps
@cacheable
def get_product_page(product_id: int, store_id: int):
# This page stays cached as long as none of these change:
add_deps([
f"prod:{product_id}",
f"store:{store_id}:inv",
f"region:eu:pricing",
"campaign:blackfriday"
])
return render_page(product_id, store_id)
# Any of these will invalidate the page:
# invalidate("prod:42")
# invalidate("store:1:inv")
# invalidate("region:eu") -> Clears ALL prices in that region
Terminal User Interface (TUI)
Zoocache comes with a built-in TUI to monitor metrics, view the caching trie, and run real-time commands such as cache invalidation.
uv run zoocache cli
📖 Documentation
Explore the deep dives into Zoocache's architecture and features:
- Architecture Overview - How the Rust core and Python wrapper interact.
- Hierarchical Invalidation - Deep dive into the PrefixTrie and O(D) invalidation.
- Serialization Pipeline - Efficient data handling with MsgPack and LZ4.
- Concurrency & SingleFlight - Shielding your database from traffic spikes.
- Distributed Consistency - HLC, Redis Bus, and robust consistency models.
- FastAPI Integration - Out-of-box caching for FastAPI endpoints.
- Litestar Integration - Out-of-box caching for Litestar endpoints.
- Django Integration - Using ZooCache with the Django ORM.
- Django User Guide - Detailed guide for Django users.
- Django Serializers Auto - Automatic caching for Django REST Framework.
- Reliability & Edge Cases - Fail-fast mechanisms and memory management.
Architectural Decisions (ADR)
- ADR 0001: Prefix-Trie Invalidation
- ADR 0002: Rust Core Python Wrapper
- ADR 0003: HLC Distributed Consistency
- ADR 0004: Serialization Strategy
- ADR 0005: SingleFlight Pattern
- ADR 0006: Trie Performance Optimizations
- ADR 0007: Zero-Bridge Serialization
- ADR 0008: Redis Bus Connection Pooling
- ADR 0009: Robust Sync and Error Handling
❓ When to Use Zoocache
✅ Good Fit
- Complex Data Relationships: Use dependencies to invalidate groups of data.
- High Read/Write Ratio: Where TTL causes stale data or unnecessary cache churn.
- Distributed Systems: Native Redis Pub/Sub invalidation and HLC consistency.
- Strict Consistency: When users must see updates immediately (e.g., pricing, inventory).
❌ Not Ideal
- Pure Time-Based Expiry: If you only need simple TTL for session tokens.
- Simple Key-Value: If you don't need dependencies or hierarchical invalidation.
- Minimal Dependencies: For small, local-only apps where basic
lru_cachesuffices.
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zoocache-2026.2.25.tar.gz.
File metadata
- Download URL: zoocache-2026.2.25.tar.gz
- Upload date:
- Size: 4.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be56c10e167acd2ad297fd703bc525f31750f0476374ca137941df60332587c6
|
|
| MD5 |
0e7d245a033305bb12d838d60e3719f8
|
|
| BLAKE2b-256 |
bfd5538cf5015bfbfc400b07835a7fd7cafa6918e68ff5a485e320d3ad79833a
|
Provenance
The following attestation bundles were made for zoocache-2026.2.25.tar.gz:
Publisher:
release.yml on albertobadia/zoocache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zoocache-2026.2.25.tar.gz -
Subject digest:
be56c10e167acd2ad297fd703bc525f31750f0476374ca137941df60332587c6 - Sigstore transparency entry: 992677661
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@56dd29ba395d3f152797ecc83cb595c7771f0043 -
Branch / Tag:
refs/tags/2026.2.25 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@56dd29ba395d3f152797ecc83cb595c7771f0043 -
Trigger Event:
release
-
Statement type:
File details
Details for the file zoocache-2026.2.25-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: zoocache-2026.2.25-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 995.3 kB
- Tags: PyPy, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
918bb96c85e7a49f43df4a122da6309fd999ada26c9079125e38aeaa92dd0b3a
|
|
| MD5 |
b443cff1ce77261e4d0010fe4c84b243
|
|
| BLAKE2b-256 |
c4fd7ec317f1ba9b1f1c5c29726d4867c8d82f87c6c40fff87450db7c515a183
|
Provenance
The following attestation bundles were made for zoocache-2026.2.25-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl:
Publisher:
release.yml on albertobadia/zoocache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zoocache-2026.2.25-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl -
Subject digest:
918bb96c85e7a49f43df4a122da6309fd999ada26c9079125e38aeaa92dd0b3a - Sigstore transparency entry: 992677667
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@56dd29ba395d3f152797ecc83cb595c7771f0043 -
Branch / Tag:
refs/tags/2026.2.25 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@56dd29ba395d3f152797ecc83cb595c7771f0043 -
Trigger Event:
release
-
Statement type:
File details
Details for the file zoocache-2026.2.25-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: zoocache-2026.2.25-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 851.3 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9fa92535eb23e204cf3a00e7d80297eea3175a2a4aa9ffb58b3ddd4b99de1f0
|
|
| MD5 |
16d9ca3744101cf8b715a84a61d4aa58
|
|
| BLAKE2b-256 |
07a12432d61591e90b1b7ac49bb5b4daaa2bf3066f6125089a6a432da6e431bf
|
Provenance
The following attestation bundles were made for zoocache-2026.2.25-cp310-abi3-win_amd64.whl:
Publisher:
release.yml on albertobadia/zoocache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zoocache-2026.2.25-cp310-abi3-win_amd64.whl -
Subject digest:
d9fa92535eb23e204cf3a00e7d80297eea3175a2a4aa9ffb58b3ddd4b99de1f0 - Sigstore transparency entry: 992677672
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@56dd29ba395d3f152797ecc83cb595c7771f0043 -
Branch / Tag:
refs/tags/2026.2.25 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@56dd29ba395d3f152797ecc83cb595c7771f0043 -
Trigger Event:
release
-
Statement type:
File details
Details for the file zoocache-2026.2.25-cp310-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: zoocache-2026.2.25-cp310-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 997.6 kB
- Tags: CPython 3.10+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd0b37363c46d09e124cf2a47c4b44aeddfa68eb774bc5306e4b7840e1fc8db1
|
|
| MD5 |
2783a8428aeaeec49c491a48e4a2e313
|
|
| BLAKE2b-256 |
3171fe346d6da9d10ba15f2131451124bb51d9e60003b9482781f505cdfea92b
|
Provenance
The following attestation bundles were made for zoocache-2026.2.25-cp310-abi3-manylinux_2_28_x86_64.whl:
Publisher:
release.yml on albertobadia/zoocache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zoocache-2026.2.25-cp310-abi3-manylinux_2_28_x86_64.whl -
Subject digest:
dd0b37363c46d09e124cf2a47c4b44aeddfa68eb774bc5306e4b7840e1fc8db1 - Sigstore transparency entry: 992677665
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@56dd29ba395d3f152797ecc83cb595c7771f0043 -
Branch / Tag:
refs/tags/2026.2.25 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@56dd29ba395d3f152797ecc83cb595c7771f0043 -
Trigger Event:
release
-
Statement type:
File details
Details for the file zoocache-2026.2.25-cp310-abi3-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: zoocache-2026.2.25-cp310-abi3-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 951.3 kB
- Tags: CPython 3.10+, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9396df1e4dfbccb4ac431b6e2605043307e28fbff6be06bdc24e43b250940494
|
|
| MD5 |
15b04afe01e49c2081b3a8f682448116
|
|
| BLAKE2b-256 |
ce9fb906f1f0557e373fc7e40156d7887c696ed344cd93ec2fc639e099bd6522
|
Provenance
The following attestation bundles were made for zoocache-2026.2.25-cp310-abi3-manylinux_2_28_aarch64.whl:
Publisher:
release.yml on albertobadia/zoocache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zoocache-2026.2.25-cp310-abi3-manylinux_2_28_aarch64.whl -
Subject digest:
9396df1e4dfbccb4ac431b6e2605043307e28fbff6be06bdc24e43b250940494 - Sigstore transparency entry: 992677670
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@56dd29ba395d3f152797ecc83cb595c7771f0043 -
Branch / Tag:
refs/tags/2026.2.25 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@56dd29ba395d3f152797ecc83cb595c7771f0043 -
Trigger Event:
release
-
Statement type:
File details
Details for the file zoocache-2026.2.25-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: zoocache-2026.2.25-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 862.4 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bcad68a84dfbc0a7574bdf5689d96a540b537b70754486411a56bb46b9c85cc
|
|
| MD5 |
bce9b7668b46b104b64e9e8e939f050a
|
|
| BLAKE2b-256 |
d2821079288987b33907dc958cf8a800432243a685c927d1b733bf8843581c84
|
Provenance
The following attestation bundles were made for zoocache-2026.2.25-cp310-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on albertobadia/zoocache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zoocache-2026.2.25-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
7bcad68a84dfbc0a7574bdf5689d96a540b537b70754486411a56bb46b9c85cc - Sigstore transparency entry: 992677678
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@56dd29ba395d3f152797ecc83cb595c7771f0043 -
Branch / Tag:
refs/tags/2026.2.25 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@56dd29ba395d3f152797ecc83cb595c7771f0043 -
Trigger Event:
release
-
Statement type:
File details
Details for the file zoocache-2026.2.25-cp310-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: zoocache-2026.2.25-cp310-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 927.9 kB
- Tags: CPython 3.10+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6436239abd7fa19d0e0715c01b13221e9a88d48f024a82d590cce11185fb08e
|
|
| MD5 |
9bc0cd214297d7c5c1dedb7ec0235092
|
|
| BLAKE2b-256 |
614a62cc0ac4e5f6c1df5159a832cb6e3d851504c5fa6ebf411da75e24f3f0db
|
Provenance
The following attestation bundles were made for zoocache-2026.2.25-cp310-abi3-macosx_10_12_x86_64.whl:
Publisher:
release.yml on albertobadia/zoocache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zoocache-2026.2.25-cp310-abi3-macosx_10_12_x86_64.whl -
Subject digest:
f6436239abd7fa19d0e0715c01b13221e9a88d48f024a82d590cce11185fb08e - Sigstore transparency entry: 992677675
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@56dd29ba395d3f152797ecc83cb595c7771f0043 -
Branch / Tag:
refs/tags/2026.2.25 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@56dd29ba395d3f152797ecc83cb595c7771f0043 -
Trigger Event:
release
-
Statement type: