Skip to main content

Cache that invalidates when your data changes, not when a timer expires. Rust-powered semantic invalidation for Python.

Project description

ZooCache Logo

Zoocache is a high-performance caching library with a Rust core, designed for applications where data consistency and read performance are critical.

Python 3.10+ License: MIT PyPI Downloads CI Benchmarks ReadTheDocs


✨ Key Features

  • 🚀 Rust-Powered Performance: Core logic implemented in Rust for ultra-low latency and safe concurrency.
  • 🧠 Semantic Invalidation: Use a PrefixTrie for 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.

🚀 Performance

Zoocache is continuously benchmarked to ensure zero performance regressions. We track micro-latency, scaling with dependencies, and storage overhead.

ZooCache Performance

Performance Context

The benchmark results reflect ZooCache's specific architectural choices:

  • Rust Core: Implementing the core logic in Rust reduces the processing time spent on internal cache management and synchronization compared to pure Python implementations.
  • Trie-based Invalidation: Instead of matching and deleting individual keys, ZooCache uses a PrefixTrie to manage dependencies. Invalidation is performed by updating versions in the trie, which remains efficient even as the number of cached items grows.
  • Pub/Sub Bus: Using Redis Pub/Sub for the invalidation bus enables low-latency propagation of invalidation signals across multiple nodes, typically completing in under 1ms.

Note: Benchmark scale: 5,000 operations. Redis is running on localhost (loopback) to eliminate network latency interference and focus on internal engine overhead. ZooCache maintains O(1) tagging overhead and scales linearly. Latency values represent the end-to-end operation time including storage overhead.

Optional CLI & TUI

Zoocache includes an optional CLI for real-time monitoring and cache management. It can be installed using the cli extra:

pip install "zoocache[cli]"

ZooCache CLI


⚖️ 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

⚡ Quick Start

Installation

Using uv (recommended):

uv add zoocache
# Or with CLI support:
uv add "zoocache[cli]"

Using pip:

pip install zoocache
# Or with CLI support:
pip install "zoocache[cli]"

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

Terminal User Interface (TUI)

Zoocache comes with a built-in TUI to monitor metrics, view the caching trie, and run real-time commands such as cache invalidation.

uv run zoocache cli

📖 Documentation

Explore the deep dives into Zoocache's architecture and features:

Architectural Decisions (ADR)


❓ 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.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zoocache-2026.2.23.tar.gz (4.5 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

zoocache-2026.2.23-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl (987.5 kB view details)

Uploaded PyPymanylinux: glibc 2.28+ x86-64

zoocache-2026.2.23-cp310-abi3-win_amd64.whl (843.2 kB view details)

Uploaded CPython 3.10+Windows x86-64

zoocache-2026.2.23-cp310-abi3-manylinux_2_28_x86_64.whl (989.3 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

zoocache-2026.2.23-cp310-abi3-manylinux_2_28_aarch64.whl (938.6 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

zoocache-2026.2.23-cp310-abi3-macosx_11_0_arm64.whl (851.2 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

zoocache-2026.2.23-cp310-abi3-macosx_10_12_x86_64.whl (919.3 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file zoocache-2026.2.23.tar.gz.

File metadata

  • Download URL: zoocache-2026.2.23.tar.gz
  • Upload date:
  • Size: 4.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for zoocache-2026.2.23.tar.gz
Algorithm Hash digest
SHA256 c5d01a50e1920b6589ca47822346ea4ab32ae9185423a58140a60568e25d13c0
MD5 7ef802c0fb975d9657dd7bd434dd8137
BLAKE2b-256 37e374f5fe18a09fc846f14d110abe0c846cd89a30261f07bf0c6dc8aca0cf03

See more details on using hashes here.

Provenance

The following attestation bundles were made for zoocache-2026.2.23.tar.gz:

Publisher: release.yml on albertobadia/zoocache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zoocache-2026.2.23-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zoocache-2026.2.23-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6e08c35cfaada5203c900071601e63f5d8db554b480c4ade97f41da387d10208
MD5 1f44616331424efac70e48799b48ddc2
BLAKE2b-256 1ecae05d99761d28b8c692674ecef8e19cdc3e3783c59d5ce33900015e4a0ecd

See more details on using hashes here.

Provenance

The following attestation bundles were made for zoocache-2026.2.23-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl:

Publisher: release.yml on albertobadia/zoocache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zoocache-2026.2.23-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: zoocache-2026.2.23-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 843.2 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

Hashes for zoocache-2026.2.23-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 91292c97e9a8cfc1d7413b4bc965c343a9687fb9a7326d2a3fe8777a2e5c459b
MD5 4fff3000cae0527dbe5e19acfea77912
BLAKE2b-256 549b858f71d955c981ef06dafc074dae7e6a6381496c62409de1d4fe838d8397

See more details on using hashes here.

Provenance

The following attestation bundles were made for zoocache-2026.2.23-cp310-abi3-win_amd64.whl:

Publisher: release.yml on albertobadia/zoocache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zoocache-2026.2.23-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zoocache-2026.2.23-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 326cf43c212a448644cee9e6817927da0a479a62e4570668c41066e8391f98cd
MD5 556cfc7858ed4f1504c0a836b54d5335
BLAKE2b-256 d64a8b87c463b9fe84362947b7b064d24c8b6eab532a3998c4c0f434c1d5ccc2

See more details on using hashes here.

Provenance

The following attestation bundles were made for zoocache-2026.2.23-cp310-abi3-manylinux_2_28_x86_64.whl:

Publisher: release.yml on albertobadia/zoocache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zoocache-2026.2.23-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for zoocache-2026.2.23-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 dfdf98b361312d93de9726b39cdd7cb3c01bad827d1aa475d3b73c6c12f6923c
MD5 7155fd77651453700f93bbb9368f447a
BLAKE2b-256 8cd3147cbb460cbc77874801bd8a840e6eedb312e84e6846e71a874a723348c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for zoocache-2026.2.23-cp310-abi3-manylinux_2_28_aarch64.whl:

Publisher: release.yml on albertobadia/zoocache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zoocache-2026.2.23-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zoocache-2026.2.23-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5d0185a6b2ee7ce7ad357534fbcb0280add55a7822d64b658daeeb443936511e
MD5 f787f7ab91179bc1cf7e00e804def413
BLAKE2b-256 b1acd8df5acf81fb0599937dce6b658b615d310d35c48e340f3ddf6cf65d6772

See more details on using hashes here.

Provenance

The following attestation bundles were made for zoocache-2026.2.23-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on albertobadia/zoocache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zoocache-2026.2.23-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for zoocache-2026.2.23-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 90a86ab973cf6a046d5f48324cbfab1e41107cf4e142cb2bc56bce38afc18277
MD5 5c59587434f21f65575577f33e77d8de
BLAKE2b-256 d60c58e4e9ac1f0c87d73d60356d10900910204855711fd2245759269700c722

See more details on using hashes here.

Provenance

The following attestation bundles were made for zoocache-2026.2.23-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on albertobadia/zoocache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page