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

❓ 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.9.tar.gz (108.3 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.9-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl (693.7 kB view details)

Uploaded PyPymanylinux: glibc 2.28+ x86-64

zoocache-2026.2.9-cp310-abi3-win_amd64.whl (580.2 kB view details)

Uploaded CPython 3.10+Windows x86-64

zoocache-2026.2.9-cp310-abi3-manylinux_2_28_x86_64.whl (696.2 kB view details)

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

zoocache-2026.2.9-cp310-abi3-manylinux_2_28_aarch64.whl (659.8 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

zoocache-2026.2.9-cp310-abi3-macosx_11_0_arm64.whl (616.0 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

zoocache-2026.2.9-cp310-abi3-macosx_10_12_x86_64.whl (662.9 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: zoocache-2026.2.9.tar.gz
  • Upload date:
  • Size: 108.3 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.9.tar.gz
Algorithm Hash digest
SHA256 ccf8cb83ce72aa543f9bdb5a72fc6056edd22445cc7a323ce8e7c95b61486e69
MD5 6c31a7d41fbfc129e94325b463394f4f
BLAKE2b-256 a52f719694e55529b7a9410c0d31f37b74d0265e1ea062579f389c6ac859fcc1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.9-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8c5f087de8e630af1f8f36470dbaa6cca463bfab3ddafb97326cb63719ea5d4c
MD5 45a29e990b6ee544356ba173792348a0
BLAKE2b-256 6c0e85c482214b1d4d1b4cd998987cada4b8e9adc6d67f89fedc36449de450d0

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: zoocache-2026.2.9-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 580.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.9-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 680420c371fc57e607f14d2320be3d768e3164253543248273de05d41419dee9
MD5 912e6c16f8a2d19a51dabd1fbf3b46c9
BLAKE2b-256 5185e48b44ac1ef1be8e9eced964b79db6b2083e5371d430d1bf30f94e4ae4e4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.9-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 18abbe5d2c56122b209af5b808586230fbeb6f0b024cef468110c43a8d0ca112
MD5 17cefe49f059c0227489563aa1ee6c7e
BLAKE2b-256 c29e97cb972678a1a7f6a5b3c6f9ff8e812d9ae8b56aac03aec46e89aba5088d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.9-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ea19ed5b93af264f306210a128e28fa2d3edd321ac240ecd4cfb721f1d4cda1e
MD5 e7c059487cfa8ec08f51b80a5ff50dae
BLAKE2b-256 78a2a701723eca274ae8517457b4a0082b6df89097cb53fae9d1fe39b455c91f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.9-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b3f223a3a2a96fca4c36920daa62a07f4447bfc3c5ac7da1b8da629f5f354f41
MD5 658c2a371ce7f59f69340f54efeb1c97
BLAKE2b-256 d00b22e38befdf9ca21f223e1720503431527555cecdb2559b5218e20c68dd83

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.9-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6c3a3b76b18c1ba8164dcdc10c8133455b1d2518c23aa106ef0b494fc415d653
MD5 f6f20dcba2d879439ffbfb69fa40ceb3
BLAKE2b-256 100ae8a068165950af80af7b0c3d285d09e091f8c9387334ccb2b9e0c2473611

See more details on using hashes here.

Provenance

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