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.

⚡ Quick Start

Installation

Using pip:

pip install zoocache

Using uv (recommended):

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

📖 Documentation

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

Architectural Decisions (ADR)


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

🚀 Performance

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


❓ 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.14.tar.gz (133.6 kB 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.14-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl (708.7 kB view details)

Uploaded PyPymanylinux: glibc 2.28+ x86-64

zoocache-2026.2.14-cp310-abi3-win_amd64.whl (594.6 kB view details)

Uploaded CPython 3.10+Windows x86-64

zoocache-2026.2.14-cp310-abi3-manylinux_2_28_x86_64.whl (711.1 kB view details)

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

zoocache-2026.2.14-cp310-abi3-manylinux_2_28_aarch64.whl (675.6 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

zoocache-2026.2.14-cp310-abi3-macosx_11_0_arm64.whl (632.4 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

zoocache-2026.2.14-cp310-abi3-macosx_10_12_x86_64.whl (677.6 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for zoocache-2026.2.14.tar.gz
Algorithm Hash digest
SHA256 e7b276024993d0a0311c6b554f51704ef0fe9a27222794514ab3153ffda41bae
MD5 6a8ae4586c8ed45245b9c96d9657fee3
BLAKE2b-256 b461102c207702314c6c4b7e96bfe5a961354fbcbafa17bff63c29b0bbf9d479

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.14-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bf1d3ee736df32be5e412a3adb19d83e57c28dab684d324985ce38a9d25be94e
MD5 7b556ab3cef0202f713c273152330508
BLAKE2b-256 e80ac7a3f1b34a3d37ee898951a332d0ef957b4cb900a5a0d78d2d32f2d394b6

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: zoocache-2026.2.14-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 594.6 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.14-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 cb36e202066b5701f7e532bab2cd1511fad7f0c22ace3e426c9a98a18ce06a97
MD5 88f9d64483c243ff56151d6f633e6d95
BLAKE2b-256 985f8b51f721665f6b9875c455e8e857c63a50816ddfc6aa9b19185cf168f76b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.14-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 46640cc3cd93dab21d30bbf7a6332a3f7edbd80ace2afcf979d1266cc9cdb070
MD5 f2215953ddf762fc4e23bf1a4d7c396e
BLAKE2b-256 af679a594243a5a920321b99a0c3998b329e8d71c1802825f266b8304d370b52

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.14-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9fecdd2e7edef89e04b77e3b5c559ac4ac1290aa26823c455e1d8960bb380e97
MD5 b4ffa1a0e95d8d1adb8aac125dddaa88
BLAKE2b-256 b228a28240716f691414f93b0a44ebffc366906c6afa585f48b59aeae0b0bbfe

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.14-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 008720401145c175893d3109dc10e5270d1e3d34dd22282c61fc2549bba83801
MD5 05888823f6a7394bb2601f9e23647393
BLAKE2b-256 dd6752815f3d3d44c73f91d4bdd920088cc922f3a6ebf8143fbad249eeee865c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.14-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 18461cf4b09df216137adfa217738ab1a0f9afbbc93a7776fd2907bf44a9d387
MD5 ccdf2a9387cab93517a1d6c119e0f45d
BLAKE2b-256 9c5dc65b5f1acc1b35452eb61af9c0d1b503ad164d664956e219e4dd6f14474b

See more details on using hashes here.

Provenance

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