Home
ZooCache is a high-performance caching library with a Rust core, designed for applications where data consistency and read performance are critical.
Start in 30 Seconds
# Install
uv add zoocache
# Use
from zoocache import cacheable, invalidate, configure, add_deps
configure() # Must configure first!
@cacheable()
def get_user(uid):
add_deps([f"user:{uid}"])
return db.fetch_user(uid) # Runs once
get_user(1) # Database
get_user(1) # Cache - instant
invalidate("user:1") # Invalidate instantly
What Problem Does ZooCache Solve?
Traditional caches use TTL (Time To Live), which creates problems:
| Problem | Description |
|---|---|
| Stale Data | Users see old data until TTL expires |
| Cache Thrashing | Data expires, all requests hit DB simultaneously |
| Manual Invalidation | You must track and invalidate every key manually |
ZooCache uses Semantic Invalidation β invalidate exactly what changed, instantly, using hierarchical dependencies.
Key Features
-
π§ Semantic Invalidation β Use a PrefixTrie for hierarchical invalidation. Clear
"user:*"to invalidate all keys related to a specific user instantly. -
π Rust-Powered Performance β Core logic implemented in Rust for ultra-low latency and safe concurrency.
-
π‘οΈ Causal Consistency β Built-in support for Hybrid Logical Clocks (HLC) ensures consistency even in distributed systems.
-
β‘ Anti-Avalanche β Protects your backend from "thundering herd" effects by coalescing concurrent identical requests.
-
π Self-Healing β Automatic synchronization via Redis Bus with robust error recovery.
-
π Observability β Built-in support for Logs, Prometheus, and OpenTelemetry.
Why ZooCache?
| Feature | πΎ ZooCache | π΄ Redis | πΆ Dogpile | diskcache |
|---|---|---|---|---|
| Semantic Invalidation | β Trie-based | β Manual | β Manual | β TTL only |
| Causal Consistency | β HLC | β Eventual | β No | β No |
| Anti-Avalanche | β Native | β No | β Locks | β No |
| Rust-powered | β Core | β No | β No | β No |
Choose Your Path
π I'm New
Learn ZooCache from scratch with our step-by-step tutorial.
β‘ I'm in a Hurry
Just show me the code I can copy-paste.
π I Use FastAPI
Cache FastAPI endpoints with @cache_endpoint.
π I Use Django
Transparent ORM caching with Django integration.
β I Use Litestar
Cache Litestar routes effortlessly.
βοΈ I Need Configuration
Storage backends, TTL, serialization options.
Performance
ZooCache is continuously benchmarked to ensure zero performance regressions.
Documentation Structure
Our documentation follows the DiΓ‘taxis framework:
| Type | Purpose | Content |
|---|---|---|
| Tutorials | Learn step-by-step | Setup |
| How-to Guides | Solve specific problems | FastAPI, Django, CLI |
| Explanations | Understand concepts | Concepts, Architecture, Invalidation |
| Reference | Find technical details | API, Configuration |
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
[**β Star us on GitHub**](https://github.com/albertobadia/zoocache) [**π Report an Issue**](https://github.com/albertobadia/zoocache/issues)