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.
Quick Start
# Install
uv add zoocache
# Use
from zoocache import cacheable, invalidate, configure, add_deps
configure() # Configure first!
@cacheable()
def get_user(uid):
add_deps([f"user:{uid}"]) # Register dependencies inside
return db.fetch_user(uid) # Runs once
get_user(1) # Database
get_user(1) # Cache - instant
invalidate("user:1") # Invalidate instantly
Why ZooCache?
Traditional caches use TTL (Time To Live), which causes stale data and cache thrashing. ZooCache uses Semantic Invalidation with a PrefixTrie to invalidate exactly what changed — instantly.
| Feature | 🐾 ZooCache | 🔴 Redis | 🐶 Dogpile | diskcache |
|---|---|---|---|---|
| Semantic Invalidation | Trie-based | Manual | Manual | TTL only |
| Smart Serialization | MsgPack+LZ4 | No | No | No |
| Distributed Sync | Redis Bus | Pub/Sub | No | No |
| Observability | Full | Basic | No | No |
Key Features
- 🧠 Semantic Invalidation: Use a
PrefixTriefor hierarchical invalidation. Clear"user:*"to invalidate all keys related to a specific user instantly. - 💾 Flexible Storage Backends: Choose between in-memory, LMDB for persistence, or Redis for distributed caching.
- 🛡️ 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.
- 📊 Observability: Built-in support for Logs, Prometheus, and OpenTelemetry.
Installation
# Using uv (recommended)
uv add zoocache
# Using pip
pip install zoocache
Optional Extras
# CLI & TUI for monitoring
uv add "zoocache[cli]"
# FastAPI integration
uv add "zoocache[fastapi]"
# Django integration
uv add "zoocache[django]"
# Litestar integration
uv add "zoocache[litestar]"
# All integrations
uv add "zoocache[cli,fastapi,django,litestar]"
# Full telemetry (Prometheus + OpenTelemetry)
uv add "zoocache[telemetry]"
Quick Start
1. Basic Caching
from zoocache import cacheable, invalidate, add_deps
@cacheable()
def get_user(user_id: int):
add_deps([f"user:{user_id}"])
return db.fetch_user(user_id)
# First call: executes the function
user = get_user(42)
# Second call: returns cached result instantly
user = get_user(42)
2. Invalidation
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
3. Hierarchical Dependencies
from zoocache import cacheable, add_deps
@cacheable()
def get_product(pid):
add_deps([f"product:{pid}"])
return db.get_product(pid)
@cacheable()
def get_reviews(pid):
add_deps([f"product:{pid}:reviews"])
return db.get_reviews(pid)
# Invalidate product AND its reviews
invalidate("product:42")
# Invalidate only reviews
invalidate("product:42:reviews")
4. Dynamic Dependencies
@cacheable()
def get_dashboard(user_id: int):
user = db.get_user(user_id)
add_deps([f"user:{user_id}"])
if user.is_admin:
reports = db.get_admin_reports()
add_deps(["reports:admin"])
return {"user": user, "reports": reports}
return {"user": user}
5. Distributed Mode
from zoocache import configure
# Configure for distributed caching
configure(
storage_url="redis://localhost:6379",
bus_url="redis://localhost:6379",
prefix="myapp_prod",
default_ttl=3600,
)
Optional CLI & TUI
ZooCache includes an optional CLI for real-time monitoring and cache management:
uv run zoocache cli
Performance
Zoocache is continuously benchmarked to ensure zero performance regressions.
Note: Benchmark scale: 5,000 operations. Redis running on localhost to eliminate network latency.
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.
Documentation
🚀 Getting Started
- Quick Start & Installation — Install and run your first cached function
🔌 Integrations
- FastAPI Integration — Out-of-box caching for FastAPI endpoints
- Django Integration — Transparent caching for Django ORM
- Litestar Integration — Out-of-box caching for Litestar endpoints
💡 Concepts & Deep Dives
- Core Concepts — Dependencies, hierarchical tags, and dynamic dependencies
- Semantic Invalidation — Deep dive into PrefixTrie and O(D) invalidation
- Distributed Consistency — HLC, Redis Bus, and consistency models
- Concurrency & SingleFlight — Shielding your database from traffic spikes
- Architecture Overview — How the Rust core and Python wrapper interact
⚙️ Configuration
- General Configuration — Configure storage, TTL, serialization
- Storage Backends — Memory, Redis, LMDB options
🛠️ How-to Guides
- CLI / TUI Usage — Monitor and manage your cache
- Telemetry & Observability — Prometheus, OpenTelemetry
📚 Reference
- API Reference — Detailed API documentation
- Reliability & Edge Cases — Fail-fast mechanisms and error handling
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
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.3.11.tar.gz.
File metadata
- Download URL: zoocache-2026.3.11.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 |
64960c7cb00e64374d07ce88c0d2682a358fff8edece55b7c884fb133efdf989
|
|
| MD5 |
231e40039169d4d0004af2d482ad379c
|
|
| BLAKE2b-256 |
393661bc3c59e7081168cf8906ce187e9cbe0247cf626cce537667eadb2147eb
|
Provenance
The following attestation bundles were made for zoocache-2026.3.11.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.3.11.tar.gz -
Subject digest:
64960c7cb00e64374d07ce88c0d2682a358fff8edece55b7c884fb133efdf989 - Sigstore transparency entry: 1081486159
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@40871120d1e7d62ed9323bc5e017ad906f0388a8 -
Branch / Tag:
refs/tags/2026.3.11 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@40871120d1e7d62ed9323bc5e017ad906f0388a8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file zoocache-2026.3.11-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: zoocache-2026.3.11-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.0 MB
- 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 |
54f34ca548084b1f2e8e50ab7b218261b867369b551bf3c8c47dff2925cb2dc6
|
|
| MD5 |
46381c69b8ea20fd055afdd393ff39a0
|
|
| BLAKE2b-256 |
6135b11cee38c9ba483993d857624a456ebf37fe7a7b0084d5560d0a8f81e469
|
Provenance
The following attestation bundles were made for zoocache-2026.3.11-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.3.11-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl -
Subject digest:
54f34ca548084b1f2e8e50ab7b218261b867369b551bf3c8c47dff2925cb2dc6 - Sigstore transparency entry: 1081486672
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@40871120d1e7d62ed9323bc5e017ad906f0388a8 -
Branch / Tag:
refs/tags/2026.3.11 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@40871120d1e7d62ed9323bc5e017ad906f0388a8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file zoocache-2026.3.11-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: zoocache-2026.3.11-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 867.8 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 |
d32fab15e3b493fc802fa2101bab9015bf49e75a9ec65131643dd6c1156fccb5
|
|
| MD5 |
9dd5d833846b573d75e360f0330a6d9c
|
|
| BLAKE2b-256 |
ff90711093949e7abc2ea3237b9f34233aee3c78ea21eab63e78e39f3d0f6502
|
Provenance
The following attestation bundles were made for zoocache-2026.3.11-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.3.11-cp310-abi3-win_amd64.whl -
Subject digest:
d32fab15e3b493fc802fa2101bab9015bf49e75a9ec65131643dd6c1156fccb5 - Sigstore transparency entry: 1081486505
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@40871120d1e7d62ed9323bc5e017ad906f0388a8 -
Branch / Tag:
refs/tags/2026.3.11 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@40871120d1e7d62ed9323bc5e017ad906f0388a8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file zoocache-2026.3.11-cp310-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: zoocache-2026.3.11-cp310-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.0 MB
- 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 |
04813f5bd44681d227140dfbaf8209d12b775dbe5a5951427b5d973a43c07f76
|
|
| MD5 |
71a6f4dc3c85385f631eac58ca612267
|
|
| BLAKE2b-256 |
92de81ff8fc8f457378c1c2a1a69a378d0ef5ba558536ff9d957ba2e06bf75f8
|
Provenance
The following attestation bundles were made for zoocache-2026.3.11-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.3.11-cp310-abi3-manylinux_2_28_x86_64.whl -
Subject digest:
04813f5bd44681d227140dfbaf8209d12b775dbe5a5951427b5d973a43c07f76 - Sigstore transparency entry: 1081486258
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@40871120d1e7d62ed9323bc5e017ad906f0388a8 -
Branch / Tag:
refs/tags/2026.3.11 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@40871120d1e7d62ed9323bc5e017ad906f0388a8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file zoocache-2026.3.11-cp310-abi3-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: zoocache-2026.3.11-cp310-abi3-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 967.0 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 |
b5bd13db519cf284312b5d3df5afdac660a63783538ffb3fefdfd3a2e3d90e07
|
|
| MD5 |
2f24c7e875cc46d4970a2f630222b1fe
|
|
| BLAKE2b-256 |
9a88b4839e3256d8c90faa54105b4ac7fb194a98d676289033c9019ed96e6dbd
|
Provenance
The following attestation bundles were made for zoocache-2026.3.11-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.3.11-cp310-abi3-manylinux_2_28_aarch64.whl -
Subject digest:
b5bd13db519cf284312b5d3df5afdac660a63783538ffb3fefdfd3a2e3d90e07 - Sigstore transparency entry: 1081486584
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@40871120d1e7d62ed9323bc5e017ad906f0388a8 -
Branch / Tag:
refs/tags/2026.3.11 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@40871120d1e7d62ed9323bc5e017ad906f0388a8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file zoocache-2026.3.11-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: zoocache-2026.3.11-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 875.2 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 |
98df2b4e41fa430de4962050e6980af9611542db85526ff5495d60535df39b24
|
|
| MD5 |
f0fe253bb8798914bb358446e92263a3
|
|
| BLAKE2b-256 |
2319695cfeb034f6b24bda665da277bd06a4195e97301be0c780b901b2c90814
|
Provenance
The following attestation bundles were made for zoocache-2026.3.11-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.3.11-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
98df2b4e41fa430de4962050e6980af9611542db85526ff5495d60535df39b24 - Sigstore transparency entry: 1081486415
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@40871120d1e7d62ed9323bc5e017ad906f0388a8 -
Branch / Tag:
refs/tags/2026.3.11 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@40871120d1e7d62ed9323bc5e017ad906f0388a8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file zoocache-2026.3.11-cp310-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: zoocache-2026.3.11-cp310-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 946.1 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 |
8b59a3c50fab256d474e0edc0e4ef22c95cdb30485fe46b1127fb5c1cba1822c
|
|
| MD5 |
b4266a28e2e092b3b6a788a281423d8a
|
|
| BLAKE2b-256 |
2f26e08d8559709bb5422ff21bc13135fb9f6ae99bcbe3a409340baa23bd418d
|
Provenance
The following attestation bundles were made for zoocache-2026.3.11-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.3.11-cp310-abi3-macosx_10_12_x86_64.whl -
Subject digest:
8b59a3c50fab256d474e0edc0e4ef22c95cdb30485fe46b1127fb5c1cba1822c - Sigstore transparency entry: 1081486322
- Sigstore integration time:
-
Permalink:
albertobadia/zoocache@40871120d1e7d62ed9323bc5e017ad906f0388a8 -
Branch / Tag:
refs/tags/2026.3.11 - Owner: https://github.com/albertobadia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@40871120d1e7d62ed9323bc5e017ad906f0388a8 -
Trigger Event:
release
-
Statement type: