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.
Release files for zoocache 2026.4.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| zoocache-2026.4.9.tar.gz | 4.6 MB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| zoocache-2026.4.9-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| zoocache-2026.4.9-cp310-abi3-manylinux_2_28_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ x86-64 | Details |
| zoocache-2026.4.9-cp310-abi3-manylinux_2_28_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ ARM64 | Details |
| zoocache-2026.4.9-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
| zoocache-2026.4.9-cp310-abi3-macosx_10_12_x86_64.whl | CPython 3.10 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 9.3 MB
Release files / zoocache-2026.4.9.tar.gz
| Download URL | zoocache-2026.4.9.tar.gz |
|---|---|
| Size | 4.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
600166cd73864d24fdcc020389682ead1f1615575036e4b322688eec7352b384
|
|
BLAKE2b-256 checksum How to use checksums |
43a9034418e275f3e147cae049cc3de98eb056891fb24b48f2f77ad51377e58f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 9, 2026.
Transparency logRelease files / zoocache-2026.4.9-cp310-abi3-win_amd64.whl
| Download URL | zoocache-2026.4.9-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 873.3 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
dbb12965b8fbfb0032965203c31b6d66e1e0ef99daa06e7f8c2fbf86a613ec64
|
|
BLAKE2b-256 checksum How to use checksums |
51c16c50dc46af0a6666dc2d914e07609eca61dddbcc76fc1ec954e6f61569e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 9, 2026.
Transparency logRelease files / zoocache-2026.4.9-cp310-abi3-manylinux_2_28_x86_64.whl
| Download URL | zoocache-2026.4.9-cp310-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
d377f10448f7c962d901eba65a244bbc3a4138811caccc577dbc6f0f62fc8f41
|
|
BLAKE2b-256 checksum How to use checksums |
330aeab864a23d68dd757501b50035ae60ff1e8cd631b8d2f724a736e960eb75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 9, 2026.
Transparency logRelease files / zoocache-2026.4.9-cp310-abi3-manylinux_2_28_aarch64.whl
| Download URL | zoocache-2026.4.9-cp310-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 972.7 kB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
75a124197b32c42021245cca1386e5bfe8d5add300961e2e8694050a6ce25575
|
|
BLAKE2b-256 checksum How to use checksums |
021d019b0c2e6e63eccd4847b9ea68040cc8130c1788846744d470eb9893cecb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 9, 2026.
Transparency logRelease files / zoocache-2026.4.9-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | zoocache-2026.4.9-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 880.1 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
5d1f0f1bdffefe7dc86bf3e0970ba674c7c55acf7195868bc4c594d5a4e70f1b
|
|
BLAKE2b-256 checksum How to use checksums |
bd3032e00a0988d45244ebfd72b4184c4db05820d62dd1e648105c0d1a3a06cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 9, 2026.
Transparency logRelease files / zoocache-2026.4.9-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | zoocache-2026.4.9-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 951.0 kB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
16467b8d74e1a641fd0829232ef6b829510be22ef0087794acf486014c806401
|
|
BLAKE2b-256 checksum How to use checksums |
39ac0a167394e1de005fb8b8d8ae9d573090a0e2076b87df6ee546e879fd2d1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 9, 2026.
Transparency log