This release is a pre-release and may not be stable for production use.
benzene-cache
Caching for Benzene Python: a cache-aside
abstraction over one narrow async Cache port, with an in-memory backend for tests and single-process
services and a Redis backend for a shared store. Depends only on benzene-core.
pip install benzene-cache # in-memory only
pip install benzene-cache[redis] # + the redis.asyncio backend
Cache is three async methods keyed on a string — get, set (with an optional TTL), delete — and
every backend is interchangeable behind it. get_or_load is the cache-aside workhorse: return the
cached value, or run the loader once, store it, and hand it back.
from benzene.cache import InMemoryCache, RedisCache, get_or_load, CacheAside
cache = InMemoryCache() # or RedisCache("redis://localhost")
async def load_profile() -> dict: # the loader may be sync or async
return await profiles.fetch(user_id)
# Cache-aside: hits the cache, and only runs the loader on a miss (then caches for 300s).
profile = await get_or_load(cache, f"profile:{user_id}", load_profile, ttl=300)
# Bind a cache + default TTL when you're repeating them.
profiles_cache = CacheAside(cache, default_ttl=300)
profile = await profiles_cache.get_or_load(f"profile:{user_id}", load_profile)
Cache— the abstraction (mirrorsBenzene.Cache.Core):async get(key) -> Any | None,async set(key, value, *, ttl=None),async delete(key). A miss returnsNoneand never raises.InMemoryCache— a dict with optional per-entry TTL and an injectableclock, so expiry is asserted without sleeping. The same shape asbenzene.resilience'sInMemoryIdempotencyStore.RedisCache— aCacheoverredis.asyncio(mirrorsBenzene.Cache.Redis). Values round-trip through JSON (benzene.core.encode_bodyon the way in,json.loadson the way out) and TTL maps toSET ... EX/PX. TheredisSDK is imported lazily, and an already-built client can be injected — so it is exercised against an in-memory fake with no SDK and no network.get_or_load/CacheAside— read-through-on-miss over anyCache; the loader is sync or async and runs exactly once per miss.
Nothing here needs Redis or a real clock to test: the in-memory cache takes an injectable clock and
the Redis cache takes an injected client, so the whole surface runs deterministically in memory.
Mirrors .NET's Benzene.Cache.Core and Benzene.Cache.Redis, and contributes the benzene.cache
subpackage to the shared benzene namespace.
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 benzene_cache-0.1.0b1.tar.gz.
File metadata
- Download URL: benzene_cache-0.1.0b1.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e21245488469d0cf00b891d950af6859ed2f7d3585019b3d5ea3f185cf35c96
|
|
| MD5 |
18ace7d95abcacafc142e143db221151
|
|
| BLAKE2b-256 |
15bab46f23b4901383d47c22645b3bd021dd521bf892fe3af81da19711da6b75
|
Provenance
The following attestation bundles were made for benzene_cache-0.1.0b1.tar.gz:
Publisher:
release.yml on daniellepelley/benzene-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
benzene_cache-0.1.0b1.tar.gz -
Subject digest:
7e21245488469d0cf00b891d950af6859ed2f7d3585019b3d5ea3f185cf35c96 - Sigstore transparency entry: 2467247426
- Sigstore integration time:
-
Permalink:
daniellepelley/benzene-python@7f3c0d2abeeb3782a82a8e2621ee8b431bf02ca8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/daniellepelley
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7f3c0d2abeeb3782a82a8e2621ee8b431bf02ca8 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file benzene_cache-0.1.0b1-py3-none-any.whl.
File metadata
- Download URL: benzene_cache-0.1.0b1-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9320149b91cf7f0f758e1a8cd49cdfcfca41665bf407c1e5e9df0d13af5355e2
|
|
| MD5 |
eb0716525fb83eeed12044be55964096
|
|
| BLAKE2b-256 |
d791e18ef97ca54769e3ac07158c8e5888f80be64ceb5cfa9a6545449f344f0e
|
Provenance
The following attestation bundles were made for benzene_cache-0.1.0b1-py3-none-any.whl:
Publisher:
release.yml on daniellepelley/benzene-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
benzene_cache-0.1.0b1-py3-none-any.whl -
Subject digest:
9320149b91cf7f0f758e1a8cd49cdfcfca41665bf407c1e5e9df0d13af5355e2 - Sigstore transparency entry: 2467192414
- Sigstore integration time:
-
Permalink:
daniellepelley/benzene-python@7f3c0d2abeeb3782a82a8e2621ee8b431bf02ca8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/daniellepelley
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7f3c0d2abeeb3782a82a8e2621ee8b431bf02ca8 -
Trigger Event:
workflow_dispatch
-
Statement type: