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.
⚡ Quick Start
Installation
Using pip:
pip install zoocache
Using uv (recommended):
uv add 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
📖 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.
- 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)
⚖️ 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 |
🚀 Performance
Zoocache is continuously benchmarked to ensure zero performance regressions. We track micro-latency, scaling with dependencies, and storage overhead.
❓ 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.20.tar.gz.
File metadata
- Download URL: zoocache-2026.2.20.tar.gz
- Upload date:
- Size: 149.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0128e9d65d2891dcba016be3301f492635fea0e24f7bc4811780e68a10ec6573
|
|
| MD5 |
1f2237d5d7605d8861c6fd17ee2ff878
|
|
| BLAKE2b-256 |
734a076acb1b6f7d418f13f808bddc57f02b522acdd53ba2fbd085d6497c9942
|
Provenance
The following attestation bundles were made for zoocache-2026.2.20.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.20.tar.gz -
Subject digest:
0128e9d65d2891dcba016be3301f492635fea0e24f7bc4811780e68a10ec6573 - Sigstore transparency entry: 973689298
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@7e7702cb28765be4d291e89f8a2434eedeaad798 -
Branch / Tag:
refs/tags/2026.2.20 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7e7702cb28765be4d291e89f8a2434eedeaad798 -
Trigger Event:
release
-
Statement type:
File details
Details for the file zoocache-2026.2.20-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: zoocache-2026.2.20-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 733.9 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 |
2a97ce2facf8e709351330c9e77cf8223689d2ebc88f6bc1a5ca4d8b93c85b55
|
|
| MD5 |
99f94fbd9aaca92c9426aca09de7cd6e
|
|
| BLAKE2b-256 |
766c5e43a054f1aec0f01afe9f5313536058e871c5de216e9d3c7f778b01ca66
|
Provenance
The following attestation bundles were made for zoocache-2026.2.20-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.20-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl -
Subject digest:
2a97ce2facf8e709351330c9e77cf8223689d2ebc88f6bc1a5ca4d8b93c85b55 - Sigstore transparency entry: 973689627
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@7e7702cb28765be4d291e89f8a2434eedeaad798 -
Branch / Tag:
refs/tags/2026.2.20 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7e7702cb28765be4d291e89f8a2434eedeaad798 -
Trigger Event:
release
-
Statement type:
File details
Details for the file zoocache-2026.2.20-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: zoocache-2026.2.20-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 619.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 |
19ab1f836c09472ff5492fae807e0404b51b7aaeb6cb057333d3c922e697b54d
|
|
| MD5 |
9a97f3e817048e07beee3d5646635362
|
|
| BLAKE2b-256 |
969be1a3e018e29acf148f26f57e673106925ecc0a45046718de9f0776e38a6d
|
Provenance
The following attestation bundles were made for zoocache-2026.2.20-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.20-cp310-abi3-win_amd64.whl -
Subject digest:
19ab1f836c09472ff5492fae807e0404b51b7aaeb6cb057333d3c922e697b54d - Sigstore transparency entry: 973689444
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@7e7702cb28765be4d291e89f8a2434eedeaad798 -
Branch / Tag:
refs/tags/2026.2.20 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7e7702cb28765be4d291e89f8a2434eedeaad798 -
Trigger Event:
release
-
Statement type:
File details
Details for the file zoocache-2026.2.20-cp310-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: zoocache-2026.2.20-cp310-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 736.0 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 |
aebe32598215f5cd7460a5046bba9a258e6b923d75574e637aa7188c8afa2835
|
|
| MD5 |
1d9402a8c9c4d62ef16ddd483ef96a9d
|
|
| BLAKE2b-256 |
55e342df4bb11d55e24d63dc5a988634c3af2e1af7140bb7b045b1ab711d6989
|
Provenance
The following attestation bundles were made for zoocache-2026.2.20-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.20-cp310-abi3-manylinux_2_28_x86_64.whl -
Subject digest:
aebe32598215f5cd7460a5046bba9a258e6b923d75574e637aa7188c8afa2835 - Sigstore transparency entry: 973689822
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@7e7702cb28765be4d291e89f8a2434eedeaad798 -
Branch / Tag:
refs/tags/2026.2.20 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7e7702cb28765be4d291e89f8a2434eedeaad798 -
Trigger Event:
release
-
Statement type:
File details
Details for the file zoocache-2026.2.20-cp310-abi3-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: zoocache-2026.2.20-cp310-abi3-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 700.2 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 |
f679fa27607cd98a032a4234f3bda73024fe04ca7b3cf2a8a448c94f19bebc8c
|
|
| MD5 |
c4e2f2420d312078b47e891446469c02
|
|
| BLAKE2b-256 |
34b6ec103150a0392b4fad2eeac8c267aaa866ff3a7d1b3c2c23416d541730ad
|
Provenance
The following attestation bundles were made for zoocache-2026.2.20-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.20-cp310-abi3-manylinux_2_28_aarch64.whl -
Subject digest:
f679fa27607cd98a032a4234f3bda73024fe04ca7b3cf2a8a448c94f19bebc8c - Sigstore transparency entry: 973689771
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@7e7702cb28765be4d291e89f8a2434eedeaad798 -
Branch / Tag:
refs/tags/2026.2.20 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7e7702cb28765be4d291e89f8a2434eedeaad798 -
Trigger Event:
release
-
Statement type:
File details
Details for the file zoocache-2026.2.20-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: zoocache-2026.2.20-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 657.1 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 |
593c5cbc10259f9a9becdb9fe45152a5ee0208eb86830d49946fa3efd4623abc
|
|
| MD5 |
1031607b2a86f73dacd6a27c2125e7c8
|
|
| BLAKE2b-256 |
2aefc9bb0bd8206fdcba44a70098110617637a6130d76da7e4d4db0bf5fe00a9
|
Provenance
The following attestation bundles were made for zoocache-2026.2.20-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.20-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
593c5cbc10259f9a9becdb9fe45152a5ee0208eb86830d49946fa3efd4623abc - Sigstore transparency entry: 973689878
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@7e7702cb28765be4d291e89f8a2434eedeaad798 -
Branch / Tag:
refs/tags/2026.2.20 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7e7702cb28765be4d291e89f8a2434eedeaad798 -
Trigger Event:
release
-
Statement type:
File details
Details for the file zoocache-2026.2.20-cp310-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: zoocache-2026.2.20-cp310-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 702.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 |
6a0d43730507a238f1e6a2fd90fffacee2e8478f72c06adebcae7f5f72435117
|
|
| MD5 |
0994b4a48e7d9336c6b10b90aa70fc7d
|
|
| BLAKE2b-256 |
dd04f41209b2431d0f684ef0ac0e9181fe6f079edd93557ba1ddedb12c554f42
|
Provenance
The following attestation bundles were made for zoocache-2026.2.20-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.20-cp310-abi3-macosx_10_12_x86_64.whl -
Subject digest:
6a0d43730507a238f1e6a2fd90fffacee2e8478f72c06adebcae7f5f72435117 - Sigstore transparency entry: 973689531
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@7e7702cb28765be4d291e89f8a2434eedeaad798 -
Branch / Tag:
refs/tags/2026.2.20 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7e7702cb28765be4d291e89f8a2434eedeaad798 -
Trigger Event:
release
-
Statement type: