Skip to main content

Async hybrid Python cache with in-memory L1, distributed L2 providers, pluggable invalidation, stampede protection, and typed decorators.

Project description

async-hybrid-cache

Async hybrid Python cache with in-memory L1 caching, optional Redis or Memcached L2 caching, pluggable invalidation, stampede protection, fail-safe stale values, and typed decorators.

Features

  • Async-first API for Python 3.12 and newer.
  • Fast in-process L1 cache with optional Redis-backed or Memcached-backed L2 storage.
  • Pluggable invalidation buses for Redis Streams, RabbitMQ, Kafka, and PostgreSQL.
  • Request stampede protection with per-key refresh coordination.
  • Fail-safe stale reads for short backend outages.
  • Typed decorators that preserve the wrapped function signature.
  • Serializer choices for JSON, pickle, and Pydantic models.

Documentation

The end-user documentation is published at https://petercinibulk.github.io/async-hybrid-cache/ and is built from docs/ with Zensical.

Install

uv add async-hybrid-cache

Install optional providers only when your application uses them:

uv add "async-hybrid-cache[redis]"
uv add "async-hybrid-cache[memcache]"
uv add "async-hybrid-cache[rabbitmq]"
uv add "async-hybrid-cache[kafka]"
uv add "async-hybrid-cache[postgres]"
uv add "async-hybrid-cache[all]"
Extra Installs Use when
redis redis You need Redis L2 storage or Redis Streams invalidation.
memcache aiomcache You need Memcached L2 storage.
rabbitmq aio-pika You use RabbitMQ as the invalidation bus.
kafka aiokafka You use Kafka as the invalidation bus.
postgres asyncpg You use PostgreSQL LISTEN/NOTIFY for invalidation.
pydantic pydantic You want Pydantic model serialization helpers.
all all provider dependencies You want every optional provider available.

Quick Start

from async_hybrid_cache import CacheOptions, AsyncHybridCache

cache = AsyncHybridCache(
    options=CacheOptions(
        ttl_seconds=60,
        fail_safe_seconds=300,
        hard_timeout_seconds=5,
        jitter_seconds=5,
    ),
)

await cache.start()


@cache.cached(lambda user_id: f"user:{user_id}")
async def get_user(user_id: str) -> dict[str, str]:
    return {"id": user_id, "name": "Peter"}


user = await get_user("123")
await get_user.remove_cached("123")
await cache.stop()

Project

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

async_hybrid_cache-0.5.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

async_hybrid_cache-0.5.0-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

Details for the file async_hybrid_cache-0.5.0.tar.gz.

File metadata

  • Download URL: async_hybrid_cache-0.5.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for async_hybrid_cache-0.5.0.tar.gz
Algorithm Hash digest
SHA256 2e9b88bd5c2a472b26e13f8f081e192c90b8d0431523c06213a257045c9663f4
MD5 b246a7b66d727a2ad65e90f817c04290
BLAKE2b-256 6e9963511e011ba1a5a8419e7df56535d11a6f8164c613033a24a10a4602bb8c

See more details on using hashes here.

Provenance

The following attestation bundles were made for async_hybrid_cache-0.5.0.tar.gz:

Publisher: release-please.yml on petercinibulk/async-hybrid-cache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file async_hybrid_cache-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for async_hybrid_cache-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b2944c5cb75e1d8c1a5001b7c54d6fe1f03c967642943e6be4960a8a18d0af5
MD5 e2ac58090695af576e28144eb3928325
BLAKE2b-256 f5303430643a2d214212915a5c5b973e2a49ce6a8f6e6fa12730d7781ba38c2a

See more details on using hashes here.

Provenance

The following attestation bundles were made for async_hybrid_cache-0.5.0-py3-none-any.whl:

Publisher: release-please.yml on petercinibulk/async-hybrid-cache

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