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.
  • 📊 Observability & Telemetry: Built-in support for Logs, Prometheus, and OpenTelemetry to monitor cache performance.

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

Architectural Decisions (ADR)


⚖️ 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.20.tar.gz (149.1 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.20-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl (733.9 kB view details)

Uploaded PyPymanylinux: glibc 2.28+ x86-64

zoocache-2026.2.20-cp310-abi3-win_amd64.whl (619.3 kB view details)

Uploaded CPython 3.10+Windows x86-64

zoocache-2026.2.20-cp310-abi3-manylinux_2_28_x86_64.whl (736.0 kB view details)

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

zoocache-2026.2.20-cp310-abi3-manylinux_2_28_aarch64.whl (700.2 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

zoocache-2026.2.20-cp310-abi3-macosx_11_0_arm64.whl (657.1 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

zoocache-2026.2.20-cp310-abi3-macosx_10_12_x86_64.whl (702.9 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: zoocache-2026.2.20.tar.gz
  • Upload date:
  • Size: 149.1 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.20.tar.gz
Algorithm Hash digest
SHA256 0128e9d65d2891dcba016be3301f492635fea0e24f7bc4811780e68a10ec6573
MD5 1f2237d5d7605d8861c6fd17ee2ff878
BLAKE2b-256 734a076acb1b6f7d418f13f808bddc57f02b522acdd53ba2fbd085d6497c9942

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.20-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2a97ce2facf8e709351330c9e77cf8223689d2ebc88f6bc1a5ca4d8b93c85b55
MD5 99f94fbd9aaca92c9426aca09de7cd6e
BLAKE2b-256 766c5e43a054f1aec0f01afe9f5313536058e871c5de216e9d3c7f778b01ca66

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: zoocache-2026.2.20-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 619.3 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.20-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 19ab1f836c09472ff5492fae807e0404b51b7aaeb6cb057333d3c922e697b54d
MD5 9a97f3e817048e07beee3d5646635362
BLAKE2b-256 969be1a3e018e29acf148f26f57e673106925ecc0a45046718de9f0776e38a6d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.20-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 aebe32598215f5cd7460a5046bba9a258e6b923d75574e637aa7188c8afa2835
MD5 1d9402a8c9c4d62ef16ddd483ef96a9d
BLAKE2b-256 55e342df4bb11d55e24d63dc5a988634c3af2e1af7140bb7b045b1ab711d6989

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.20-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f679fa27607cd98a032a4234f3bda73024fe04ca7b3cf2a8a448c94f19bebc8c
MD5 c4e2f2420d312078b47e891446469c02
BLAKE2b-256 34b6ec103150a0392b4fad2eeac8c267aaa866ff3a7d1b3c2c23416d541730ad

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.20-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 593c5cbc10259f9a9becdb9fe45152a5ee0208eb86830d49946fa3efd4623abc
MD5 1031607b2a86f73dacd6a27c2125e7c8
BLAKE2b-256 2aefc9bb0bd8206fdcba44a70098110617637a6130d76da7e4d4db0bf5fe00a9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.20-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6a0d43730507a238f1e6a2fd90fffacee2e8478f72c06adebcae7f5f72435117
MD5 0994b4a48e7d9336c6b10b90aa70fc7d
BLAKE2b-256 dd04f41209b2431d0f684ef0ac0e9181fe6f079edd93557ba1ddedb12c554f42

See more details on using hashes here.

Provenance

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