Skip to content

Home

ZooCache Logo

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

β†’ Full Quick Start


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.

β†’ Getting Started

⚑ I'm in a Hurry

Just show me the code I can copy-paste.

β†’ Quick Examples

🌐 I Use FastAPI

Cache FastAPI endpoints with @cache_endpoint.

β†’ FastAPI Guide

πŸŒ‰ I Use Django

Transparent ORM caching with Django integration.

β†’ Django Guide

⭐ I Use Litestar

Cache Litestar routes effortlessly.

β†’ Litestar Guide

βš™οΈ I Need Configuration

Storage backends, TTL, serialization options.

β†’ Configuration


Performance

ZooCache is continuously benchmarked to ensure zero performance regressions.

ZooCache Performance


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_cache suffices

[**⭐ Star us on GitHub**](https://github.com/albertobadia/zoocache) [**πŸ› Report an Issue**](https://github.com/albertobadia/zoocache/issues)