Async-first multi-backend cache (memory, Redis, Memcached, disk, SQLite); sync helpers for scripts; tag invalidation, optional HTTP middleware, metrics
Project description
yokedcache
Async-first caching with the same API across backends: in-process memory (works out of the box), Redis, Memcached, disk, and SQLite. Tag and pattern invalidation, optional HTTP middleware, and production metrics built in.
Use await in FastAPI, Django async views, workers, or plain asyncio. Sync code is welcome too—get_sync / set_sync / @cached on a normal def run the same async implementation, no separate client needed.
Documentation · Changelog · PyPI · Issues
What's included
- Multiple backends — Memory (zero deps), Redis, Memcached, disk, SQLite; per-prefix routing to mix them
- Invalidation — Tag-based, pattern-based, and auto-invalidation on DB writes
- Sync + async — Full async API; sync helpers for scripts and blocking code
- HTTP middleware — ETag /
Cache-Controlvia Starlette (yokedcache[web]) - Resilience — Circuit breaker, retries, stale-if-error
- Observability — Prometheus, StatsD, OpenTelemetry (optional extras)
- CLI — Inspect keys, stats, and run health checks from the shell
Installation
pip install yokedcache
The base install ships with an in-process memory backend—no Redis required to get started. Add extras when you need them:
| Extra | What it adds |
|---|---|
redis |
Redis backend via redis-py |
web |
Starlette HTTP cache middleware |
backends |
Disk, SQLite, and Memcached deps together |
observability |
Prometheus, StatsD, OpenTelemetry |
full |
Everything above plus fuzzy search, vector search, SQLAlchemy helpers |
To require a minimum patch line (for example after a security release): pip install "yokedcache>=1.0.2".
Individual extras: memcached, disk, sqlite, monitoring, tracing, vector, fuzzy, sqlalchemy.
Quick start
Async (memory backend, no Redis needed):
import asyncio
from yokedcache import YokedCache
from yokedcache.config import CacheConfig
async def main():
cache = YokedCache(CacheConfig())
await cache.connect()
await cache.set("user:1", {"name": "Ada"}, ttl=60)
print(await cache.get("user:1"))
await cache.disconnect()
asyncio.run(main())
Sync (scripts and blocking code):
import asyncio
from yokedcache import YokedCache
from yokedcache.config import CacheConfig
cache = YokedCache(CacheConfig())
asyncio.run(cache.connect())
cache.set_sync("user:1", {"name": "Ada"}, ttl=60)
print(cache.get_sync("user:1"))
asyncio.run(cache.disconnect())
For Redis: pip install "yokedcache[redis]", then set redis_url="redis://..." on CacheConfig (or the env var YOKEDCACHE_REDIS_URL).
FastAPI example
from fastapi import FastAPI, Depends
from yokedcache import cached_dependency
app = FastAPI()
cached_get_db = cached_dependency(get_db, ttl=300)
@app.get("/users/{user_id}")
async def get_user(user_id: int, db=Depends(cached_get_db)):
return db.query(User).filter(User.id == user_id).first()
Requirements
- Python 3.10+ (tested on 3.10–3.14)
- Redis is optional; install
yokedcache[redis]and point to a Redis 6+ server when you want a shared remote cache
Python 3.9 is not supported on 1.x. Pin yokedcache==0.3.0 only as a temporary bridge—it does not receive security fixes. Upgrade when you can.
Security
Treat Redis and Memcached as trusted stores—anyone who can write arbitrary keys can affect what your app deserializes. Set allow_legacy_insecure_deserialization=False on CacheConfig once you've migrated away from legacy entries.
The optional disk extra pulls in diskcache. From 1.0.2, the disk backend stores JSON-safe wrappers around the same bytes envelope as other backends (no pickle for cached payloads). CVE-2025-69872 still applies to the upstream package metadata until a patched wheel ships—automated scanners may flag it. Skip the disk extra if you don't need it; keep the cache directory non-world-writable if you do. See SECURITY.md.
Development
python3 -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest
Build the docs site locally:
pip install -e ".[docs]"
python scripts/build_docs_site.py
cp CHANGELOG.md site/changelog.md
python -m pdoc yokedcache -o site/api --template-directory site-src/pdoc-template
cd site && python -m http.server 8000
See CONTRIBUTING.md for the full workflow.
License
MIT. See LICENSE.
Maintained by Project Yoked LLC; technical lead Joshua Kac.
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 yokedcache-1.0.2.tar.gz.
File metadata
- Download URL: yokedcache-1.0.2.tar.gz
- Upload date:
- Size: 1.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c97f6dbba4d82e2190910667149cf1d18dc382f68aaef20b58c6d50404f0df99
|
|
| MD5 |
a3047360539140a253970887db679fa4
|
|
| BLAKE2b-256 |
2326714f831c2271de8c5feb978db82a0bf6241030647daf1f82ad3db86b2274
|
Provenance
The following attestation bundles were made for yokedcache-1.0.2.tar.gz:
Publisher:
publish.yml on SirStig/yokedcache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yokedcache-1.0.2.tar.gz -
Subject digest:
c97f6dbba4d82e2190910667149cf1d18dc382f68aaef20b58c6d50404f0df99 - Sigstore transparency entry: 1309004646
- Sigstore integration time:
-
Permalink:
SirStig/yokedcache@75ff19acbe166f8eb84251e0a044a2fa703976f5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/SirStig
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@75ff19acbe166f8eb84251e0a044a2fa703976f5 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file yokedcache-1.0.2-py3-none-any.whl.
File metadata
- Download URL: yokedcache-1.0.2-py3-none-any.whl
- Upload date:
- Size: 80.6 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 |
1628d1312e8275247b82c1ca6e0945a82e21b460bd9dde775f288f6f377e3148
|
|
| MD5 |
5ae9e7c21573649b65d12e7f2fc6e65e
|
|
| BLAKE2b-256 |
92ddc8c4187ecaf074c4dae5c55073060fdb3a89717f4d6dc8da688687e17f7b
|
Provenance
The following attestation bundles were made for yokedcache-1.0.2-py3-none-any.whl:
Publisher:
publish.yml on SirStig/yokedcache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yokedcache-1.0.2-py3-none-any.whl -
Subject digest:
1628d1312e8275247b82c1ca6e0945a82e21b460bd9dde775f288f6f377e3148 - Sigstore transparency entry: 1309004753
- Sigstore integration time:
-
Permalink:
SirStig/yokedcache@75ff19acbe166f8eb84251e0a044a2fa703976f5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/SirStig
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@75ff19acbe166f8eb84251e0a044a2fa703976f5 -
Trigger Event:
workflow_dispatch
-
Statement type: