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

Uploaded PyPymanylinux: glibc 2.28+ x86-64

zoocache-2026.2.8-cp310-abi3-win_amd64.whl (582.8 kB view details)

Uploaded CPython 3.10+Windows x86-64

zoocache-2026.2.8-cp310-abi3-manylinux_2_28_x86_64.whl (698.1 kB view details)

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

zoocache-2026.2.8-cp310-abi3-manylinux_2_28_aarch64.whl (662.4 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

zoocache-2026.2.8-cp310-abi3-macosx_11_0_arm64.whl (618.5 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

zoocache-2026.2.8-cp310-abi3-macosx_10_12_x86_64.whl (665.4 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: zoocache-2026.2.8.tar.gz
  • Upload date:
  • Size: 108.2 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.8.tar.gz
Algorithm Hash digest
SHA256 25530ffd5b5cca1fecfd73485cc0bab1a773ce1aec37b3299cc481f436992b0e
MD5 16fb95a14b9e6560077da577daff0a24
BLAKE2b-256 2f77268f5816fd0ce70acf63879aeca95b8c4514fde267e47fec3a3cc001c1ee

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.8-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 68dfd5421d4ae0134b974054caf6ff0f28353dbf6290bc5f3c670f248095062c
MD5 debd33f2c12dca7933b1c486dd256aa3
BLAKE2b-256 5889ecc1db851922e96c109d7112a36eabe7664e048cb2321aa1c7943da6f6cf

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: zoocache-2026.2.8-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 582.8 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.8-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1f4148b909e9f9a6213b65266c448bc6fe9d0fdf1e2c38f183b945085c58e992
MD5 a45c259216c579328113d758d36def4c
BLAKE2b-256 aca7de4900de4cd7b367bb551fc73755de60abaa1600945e69f5c8f9d3ad5bc7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.8-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 252d81e0f34d03c63d9898afea793385f91e5b36c0780a137d1b65e86934d3be
MD5 a52c094dc9c5fac6c0db79ba170811f9
BLAKE2b-256 79261408dd6d3fc7afd22fe8b8614e22c05e59634921018c3a1a3be07aba22f2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.8-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d391a71ef3c88bc4573b71cb3fe3aee5bbd847e8df71dbbae946df8e7a6cd4cd
MD5 5b5f1d47aeda8b563bf7631c759f78e2
BLAKE2b-256 48faeb5c8fdf8b10e791364e7a458e159e95621504fd57d701521cf3ad7aa3e9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.8-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 590a52f41402c131d8c2502c5d23b1559a6d29e8198e8327cf9778ac01975589
MD5 f5ee531a3afe03985e40048dd360b412
BLAKE2b-256 1182bf0d12964e727a97cc915d0ea5a47f8855f8a030185f906fe26ecbc1f261

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.8-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 43eb62390dc49d1fb365c33ad9046958e1bdcc229a48b7529bd5fb2acfc10424
MD5 170633484ef56a3aa2611d4e8fc06856
BLAKE2b-256 8d0c23c8e4ef96ba1bc5de3826e55b9234ee0bb08fd424249931c484996cea48

See more details on using hashes here.

Provenance

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