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
- License: MIT
- Source: https://github.com/petercinibulk/async-hybrid-cache
- Issues: https://github.com/petercinibulk/async-hybrid-cache/issues
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e9b88bd5c2a472b26e13f8f081e192c90b8d0431523c06213a257045c9663f4
|
|
| MD5 |
b246a7b66d727a2ad65e90f817c04290
|
|
| BLAKE2b-256 |
6e9963511e011ba1a5a8419e7df56535d11a6f8164c613033a24a10a4602bb8c
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
async_hybrid_cache-0.5.0.tar.gz -
Subject digest:
2e9b88bd5c2a472b26e13f8f081e192c90b8d0431523c06213a257045c9663f4 - Sigstore transparency entry: 1940060728
- Sigstore integration time:
-
Permalink:
petercinibulk/async-hybrid-cache@968586d369979a3368d7f754f5e3a285ea3f43e3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/petercinibulk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yml@968586d369979a3368d7f754f5e3a285ea3f43e3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file async_hybrid_cache-0.5.0-py3-none-any.whl.
File metadata
- Download URL: async_hybrid_cache-0.5.0-py3-none-any.whl
- Upload date:
- Size: 21.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b2944c5cb75e1d8c1a5001b7c54d6fe1f03c967642943e6be4960a8a18d0af5
|
|
| MD5 |
e2ac58090695af576e28144eb3928325
|
|
| BLAKE2b-256 |
f5303430643a2d214212915a5c5b973e2a49ce6a8f6e6fa12730d7781ba38c2a
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
async_hybrid_cache-0.5.0-py3-none-any.whl -
Subject digest:
1b2944c5cb75e1d8c1a5001b7c54d6fe1f03c967642943e6be4960a8a18d0af5 - Sigstore transparency entry: 1940060881
- Sigstore integration time:
-
Permalink:
petercinibulk/async-hybrid-cache@968586d369979a3368d7f754f5e3a285ea3f43e3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/petercinibulk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yml@968586d369979a3368d7f754f5e3a285ea3f43e3 -
Trigger Event:
push
-
Statement type: