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.

⚡ 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.5.tar.gz (103.5 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.5-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl (681.1 kB view details)

Uploaded PyPymanylinux: glibc 2.28+ x86-64

zoocache-2026.2.5-cp310-abi3-win_amd64.whl (568.9 kB view details)

Uploaded CPython 3.10+Windows x86-64

zoocache-2026.2.5-cp310-abi3-manylinux_2_28_x86_64.whl (683.8 kB view details)

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

zoocache-2026.2.5-cp310-abi3-manylinux_2_28_aarch64.whl (648.5 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

zoocache-2026.2.5-cp310-abi3-macosx_11_0_arm64.whl (606.3 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

zoocache-2026.2.5-cp310-abi3-macosx_10_12_x86_64.whl (651.3 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: zoocache-2026.2.5.tar.gz
  • Upload date:
  • Size: 103.5 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.5.tar.gz
Algorithm Hash digest
SHA256 2f300429a0eed724e9804f9669fbbae90646f0cb38b6378ff6321a2b3a7eb58f
MD5 09eae4111e5c4648b543709d4356f402
BLAKE2b-256 a675c7a21b61c5a215cddbde8355c331bcbda902f359ee83aaa1d5db789c6887

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.5-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 67c32a9593e7ddf6e392d5d3a7baa535575e7d180e235df53ce57e2ea1f36b8c
MD5 2fc30791bff26fb5529e513079dedf10
BLAKE2b-256 dd19b76ff5866588cafed33772ad69768c395ef298be56a4156844ed977352c2

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: zoocache-2026.2.5-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 568.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.5-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 0a5f0bab8d0b745071ea594818e63a176480419e26bce77543ac037643bfbf67
MD5 fbe64d9e2a7f01f313a436c3be1ac20e
BLAKE2b-256 8017c4dc981f6842b95526ebc9a9a682f4932885be095bd6c94e0c143edef9b4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.5-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c482091c40df07f8568f4a6d8ac428d84c3e1699de0403e705ac78650ce7c169
MD5 75a8b14a5e65616cfce5964c5496630a
BLAKE2b-256 b80ef342867a8513f1375789095224d2df1e8cced10071c9d12d0ac7f8c6dba9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.5-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8dd64fc45e4072aac9e65c87886829d01dbac359955e908c73f46c3df07ba6c1
MD5 b909800c89d56968e2118b61af6ca5ab
BLAKE2b-256 ff17769cb8e32df75413cdbc32451947fd6bf1d31cac730bef721b9a24368f68

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.5-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6627963c8446f2aededd92674a213b9ca8f364c295bbe338801e0e18a79eef5b
MD5 a86ee1c990e66df35fa0a56b239b607f
BLAKE2b-256 70802a9b054fb85b1a3f40143f241f4ae2fe96ff0be7cf4b1f69b89620f30da8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for zoocache-2026.2.5-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d8c2711a2fa3c2fae7ec1f98d01425d43ea3a9035ef726ad1ad6f4673aea63e6
MD5 275985a81b01801addef54c05df24ae5
BLAKE2b-256 9cd42d29e38262a2111bdfa2b7436b2fe3412a4b542d02c774fa4ce81a457feb

See more details on using hashes here.

Provenance

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