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:


⚖️ 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.11.post1.tar.gz (122.0 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.11.post1-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl (696.3 kB view details)

Uploaded PyPymanylinux: glibc 2.28+ x86-64

zoocache-2026.2.11.post1-cp310-abi3-win_amd64.whl (583.0 kB view details)

Uploaded CPython 3.10+Windows x86-64

zoocache-2026.2.11.post1-cp310-abi3-manylinux_2_28_x86_64.whl (698.8 kB view details)

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

zoocache-2026.2.11.post1-cp310-abi3-manylinux_2_28_aarch64.whl (662.6 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

zoocache-2026.2.11.post1-cp310-abi3-macosx_11_0_arm64.whl (619.0 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

zoocache-2026.2.11.post1-cp310-abi3-macosx_10_12_x86_64.whl (665.9 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file zoocache-2026.2.11.post1.tar.gz.

File metadata

  • Download URL: zoocache-2026.2.11.post1.tar.gz
  • Upload date:
  • Size: 122.0 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.11.post1.tar.gz
Algorithm Hash digest
SHA256 ceb2ba4e19da8e48f3b2fcc9fc3d8612c6b4c05ff5074157b7578ada3d30ebc0
MD5 9e83648b335121c535c3a2ebcd21cdf1
BLAKE2b-256 c24aae36c3806d97d93569bb3359a2f9f08e76de9581caff0e3e1c20aacbc569

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.11.post1-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 015f97a8044a4bce35bff853ab37848c4c1e45dc61664325f82394f0e04fa919
MD5 48488309bd6972cdd1b3885de34b3081
BLAKE2b-256 34206a2ff51911bf97298a2f29c3b4c1f86472ebeff17129139b3d175060e28e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.11.post1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2a5a3942b69e41df90cb57984d3f5089fbc8a55ab240c1b0b6ff5d1b8b77fe8c
MD5 2bfaf372be0872a3b57b457a3bd1042a
BLAKE2b-256 7c3afa10cef09d2383f91248e431331317289003f11c2f7e77c35fc6c2a6127f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.11.post1-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 72038b6d3990627b4f4f411a885eff13e067679222b3fa8a24caa210e7258765
MD5 95246d6052e482fbb0a44a26d76e046a
BLAKE2b-256 2522acff04e1b390f2dc33d62a344d28cd22eefc2f8dae99166bc9c3df86f59f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.11.post1-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8c10846eb6a83f3af57f4c90770589f19d9adc3c66dff0f9d6d2caf2a88125ab
MD5 1cb82b4fb1f25991fbfe7ed2c1f77fd5
BLAKE2b-256 bb6593caf28a562fcdfef59c3966077fbf47b1c58742795092575000520c7be6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.11.post1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 67f34ceb173fbd642f6ff2e6b776e9f2ca4aff37f7ba7cb6a0fa486a288c970e
MD5 d2b6571d9cb2e3e513a68c0c9a10655b
BLAKE2b-256 51f4054425f56a5f961891dc590b53af7bdd6f2c28ca3342a99416d787ea1ead

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.11.post1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 dec8721343480fa76b0ed33d1bcaaef1cd9ac41084c6ff4d6998e8dcb7c9a7a4
MD5 f93bf3a89aed66e19becc8a18a46e3b3
BLAKE2b-256 72810dfc2f7a932534b49bf667b2f96f347eba0184960698b7b903f8a2cec402

See more details on using hashes here.

Provenance

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