Skip to main content
Pre-release

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 (mirrors Benzene.Cache.Core): async get(key) -> Any | None, async set(key, value, *, ttl=None), async delete(key). A miss returns None and never raises.
  • InMemoryCache — a dict with optional per-entry TTL and an injectable clock, so expiry is asserted without sleeping. The same shape as benzene.resilience's InMemoryIdempotencyStore.
  • RedisCache — a Cache over redis.asyncio (mirrors Benzene.Cache.Redis). Values round-trip through JSON (benzene.core.encode_body on the way in, json.loads on the way out) and TTL maps to SET ... EX/PX. The redis SDK 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 any Cache; 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.

Metadata

Release files for benzene-cache 0.1.0b2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for benzene-cache 0.1.0b2
File Size Uploaded Provenance Actions
benzene_cache-0.1.0b2.tar.gz 6.2 kB With provenance Details for benzene_cache-0.1.0b2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for benzene-cache 0.1.0b2
File Interpreter ABI Platform Actions
benzene_cache-0.1.0b2-py3-none-any.whl Python 3 none any Details for benzene_cache-0.1.0b2-py3-none-any.whl

Total release size: 15.1 kB

Release files / benzene_cache-0.1.0b2.tar.gz

Download URL benzene_cache-0.1.0b2.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d9e9ef03963ade8c6b7a45012c6526a93e6d8177f9246979f9f97b74ad22d328
BLAKE2b-256 checksum
How to use checksums
0f0a5e07c32f5caeac98aebb9916b4c6df2dcef1381404e2335ff813447deccc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Release files / benzene_cache-0.1.0b2-py3-none-any.whl

Download URL benzene_cache-0.1.0b2-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1497da56a6a1152290ee1146b07578cdbd3ef9bb71c979e37863a05fbe897aa0
BLAKE2b-256 checksum
How to use checksums
059e09dab4861745d99ecaab18aa2cbff21d352584d02819714d276991d884cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Security for benzene-cache 0.1.0b2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for benzene_cache-0.1.0b2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page