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

Uploaded PyPymanylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.10+Windows x86-64

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

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

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

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

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

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: zoocache-2026.2.11.tar.gz
  • Upload date:
  • Size: 121.8 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.tar.gz
Algorithm Hash digest
SHA256 390854627030d488e26a483633686e8349a89e6b344bbc5285a41472cb9a1147
MD5 f7fb95f4b3fc82f5e5d40798c0fa56c9
BLAKE2b-256 a8884dbffaf12fd16df1ce30bb07e9ec5926e5abff908d53c3f1a454bd6b9323

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.11-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 86eae6f8101d0411fa456201d2e0b67d8e553a81d7ba2e408cf569413dd1c8fc
MD5 ce71fec71f0e821ae28df1cb4e058a09
BLAKE2b-256 7b4595dc8028e6308a6542da5cb5fa75c6c76b6d459310b616d28ed70b772ec6

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: zoocache-2026.2.11-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 582.9 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.11-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 891bf9bc7f5bb2806728a5dfcfab96e67f70d06723b854a6deea1168b4cc520b
MD5 67c764ad6503e0ef0993f0bee33de6e5
BLAKE2b-256 4b2a710e5d5bad09006b681ad9877c20e00b0a5a48105ff4eb7ba8e7b9ae58a5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.11-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 238177aeb0db1f06222878da40621c35cdb3f856cc26d543b02989c7bda40a2b
MD5 13d9d4fadfeb88e405ead18d50692c32
BLAKE2b-256 9050795b8dce1a44635727e8013c82e87db6c2168ce75dac10a85686650e22a0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.11-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d14a493dc12bdb3a30a8b6b88d4fdb1e86a360d74a5cef88264bb08c983b75fe
MD5 c4b3dc40da8c5beb36b04b663d2ca8eb
BLAKE2b-256 3252c4041fc1333a9b97637c70990c8b43b5492242ef34a3d6e4c33fb27c62cd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.11-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e84165be66cff532bcf1bd52b85c53778195e09fff3a8ead17d3b83fa5051ac1
MD5 0555e03db86ea0782c273ac7039879cb
BLAKE2b-256 ffc1a5d56d0d448a1ae483407538880fe1155e24d882f3459ae277f3d43bc946

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.11-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fc9bfa0a3ef1b9daa921aec0daef6db0d1da7f7d828af6d9f7ad45427656aa90
MD5 42ab8c8d1f74b9ed03d70f4a5ac52a94
BLAKE2b-256 fca79490081331efd0d66006a71573a8907aa5a05c7a43781a4238772a18c4da

See more details on using hashes here.

Provenance

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