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


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

⚡ 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.1.20.tar.gz (71.9 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.1.20-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl (934.6 kB view details)

Uploaded PyPymanylinux: glibc 2.28+ x86-64

zoocache-2026.1.20-cp310-abi3-win_amd64.whl (713.7 kB view details)

Uploaded CPython 3.10+Windows x86-64

zoocache-2026.1.20-cp310-abi3-manylinux_2_28_x86_64.whl (938.3 kB view details)

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

zoocache-2026.1.20-cp310-abi3-manylinux_2_28_aarch64.whl (916.7 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

zoocache-2026.1.20-cp310-abi3-macosx_11_0_arm64.whl (843.3 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

zoocache-2026.1.20-cp310-abi3-macosx_10_12_x86_64.whl (869.3 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for zoocache-2026.1.20.tar.gz
Algorithm Hash digest
SHA256 e82f1d0603d11d6b4d06651616b6d350538ab47707e045729cf0bf0341aed125
MD5 9d6d69042227019591f0f9cdb02ee4a5
BLAKE2b-256 fa24c51bef577fd1cf8d422c37b56213663202a12eb2ad83ebae8aac248472ed

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.1.20-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d9871e912f2528e2b35982bc9aeb8fd85619aaa9d00b4a1b489124fe3844ea7f
MD5 1c4184fa34358755e79e300aec8e2635
BLAKE2b-256 eb2a989618204e4af45c8ff4405b4ab9e62af3f15349e458d36ee2827a90adba

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: zoocache-2026.1.20-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 713.7 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.1.20-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 bc0ec5c9b9c0051890553abb91d6f51b3c2f3d34766aaf58bf2f81540dc75d09
MD5 33cfed615a0d160808ed809761a88976
BLAKE2b-256 c091450e780c5ab608df93848846bd1628b2227f19fffad82408a67486ced209

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.1.20-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8e74fb86b4b16b19a75d641f21254b095a447243dcede81e1cdeaaca384e9dc2
MD5 42342d1237c1dae98d3ad336fe126093
BLAKE2b-256 08cadb83f4c1460e11fcd52e593a74322c39def2f29bcf3e05d6cb84524396b6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.1.20-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 36095d1747aadae4789a6ca08f873d0cad9f03c4629e1e1b97f80488771e9863
MD5 28006be2eaeb1fd30d29e4d5ce206d10
BLAKE2b-256 fcf451ea6fc970ef62d6474e4cfecfcb7902dbfc9b40d85292e22af7f367d919

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.1.20-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 96ea86cb5955b463111c26be7c6b378044fd39378cbd965ebe5f8fe8b514aa11
MD5 c00acb4223d96954e12d7722c4ae8b70
BLAKE2b-256 cb5587f77b31d8fa33c7108abbdede7c253a464c49ca5ba4a35fca1c60a55544

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.1.20-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 534105be3e03c63078b66f9e242e3268b288cb44571125601117dff841d8e960
MD5 4313fd38779173b3b45a141365ac4333
BLAKE2b-256 f254fb5f1fa8e92943513626241eda2225a9f3358b8b4cbd37df76ade3ea22ca

See more details on using hashes here.

Provenance

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