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:

uv add "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

Using pip:

pip install zoocache

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.25.tar.gz (4.6 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.25-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl (995.3 kB view details)

Uploaded PyPymanylinux: glibc 2.28+ x86-64

zoocache-2026.2.25-cp310-abi3-win_amd64.whl (851.3 kB view details)

Uploaded CPython 3.10+Windows x86-64

zoocache-2026.2.25-cp310-abi3-manylinux_2_28_x86_64.whl (997.6 kB view details)

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

zoocache-2026.2.25-cp310-abi3-manylinux_2_28_aarch64.whl (951.3 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

zoocache-2026.2.25-cp310-abi3-macosx_11_0_arm64.whl (862.4 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

zoocache-2026.2.25-cp310-abi3-macosx_10_12_x86_64.whl (927.9 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: zoocache-2026.2.25.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

Hashes for zoocache-2026.2.25.tar.gz
Algorithm Hash digest
SHA256 be56c10e167acd2ad297fd703bc525f31750f0476374ca137941df60332587c6
MD5 0e7d245a033305bb12d838d60e3719f8
BLAKE2b-256 bfd5538cf5015bfbfc400b07835a7fd7cafa6918e68ff5a485e320d3ad79833a

See more details on using hashes here.

Provenance

The following attestation bundles were made for zoocache-2026.2.25.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.25-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zoocache-2026.2.25-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 918bb96c85e7a49f43df4a122da6309fd999ada26c9079125e38aeaa92dd0b3a
MD5 b443cff1ce77261e4d0010fe4c84b243
BLAKE2b-256 c4fd7ec317f1ba9b1f1c5c29726d4867c8d82f87c6c40fff87450db7c515a183

See more details on using hashes here.

Provenance

The following attestation bundles were made for zoocache-2026.2.25-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.25-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: zoocache-2026.2.25-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 851.3 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.25-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d9fa92535eb23e204cf3a00e7d80297eea3175a2a4aa9ffb58b3ddd4b99de1f0
MD5 16d9ca3744101cf8b715a84a61d4aa58
BLAKE2b-256 07a12432d61591e90b1b7ac49bb5b4daaa2bf3066f6125089a6a432da6e431bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for zoocache-2026.2.25-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.25-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zoocache-2026.2.25-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dd0b37363c46d09e124cf2a47c4b44aeddfa68eb774bc5306e4b7840e1fc8db1
MD5 2783a8428aeaeec49c491a48e4a2e313
BLAKE2b-256 3171fe346d6da9d10ba15f2131451124bb51d9e60003b9482781f505cdfea92b

See more details on using hashes here.

Provenance

The following attestation bundles were made for zoocache-2026.2.25-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.25-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for zoocache-2026.2.25-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9396df1e4dfbccb4ac431b6e2605043307e28fbff6be06bdc24e43b250940494
MD5 15b04afe01e49c2081b3a8f682448116
BLAKE2b-256 ce9fb906f1f0557e373fc7e40156d7887c696ed344cd93ec2fc639e099bd6522

See more details on using hashes here.

Provenance

The following attestation bundles were made for zoocache-2026.2.25-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.25-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zoocache-2026.2.25-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7bcad68a84dfbc0a7574bdf5689d96a540b537b70754486411a56bb46b9c85cc
MD5 bce9b7668b46b104b64e9e8e939f050a
BLAKE2b-256 d2821079288987b33907dc958cf8a800432243a685c927d1b733bf8843581c84

See more details on using hashes here.

Provenance

The following attestation bundles were made for zoocache-2026.2.25-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.25-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for zoocache-2026.2.25-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f6436239abd7fa19d0e0715c01b13221e9a88d48f024a82d590cce11185fb08e
MD5 9bc0cd214297d7c5c1dedb7ec0235092
BLAKE2b-256 614a62cc0ac4e5f6c1df5159a832cb6e3d851504c5fa6ebf411da75e24f3f0db

See more details on using hashes here.

Provenance

The following attestation bundles were made for zoocache-2026.2.25-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