quadkit-cache
Multi-backend caching system for Quadkit Framework — Redis, Memcached, and in-memory caching.
Overview
Multi-backend async caching for the Quadkit Framework. Supports Redis, in-memory,
and Memcached backends with stampede protection, circuit breaker, Result-aware
caching, and domain model round-trip serialization.
Configure backends via CacheModule.configure() and inject CacheBackendProtocol
into any service. The @cacheable decorator provides cache-aside logic with
automatic key generation and Result support.
Full documentation: docs.quadkit.dev
Install
uv add quadkit-cache
# Optional extras
uv add "quadkit-cache[redis,memcached,semantic]"
Quick Start
from quadkit import Application
from quadkit.di.module import Module, module
from quadkit.cache import CacheModule, CacheConfig
from quadkit.cache.config import CacheBackendConfig
from quadkit.cache.types import BackendType
from quadkit.contracts.infra.cache import CacheBackendProtocol
@module(
imports=[
CacheModule.configure(
CacheConfig(
backends=[
CacheBackendConfig(
name="default",
type=BackendType.REDIS,
default=True,
redis_url="redis://localhost:6379/0",
)
]
)
)
]
)
class AppModule(Module):
pass
async def main():
async with Application.boot(modules=[AppModule]) as app:
cache = await app.container.resolve(CacheBackendProtocol)
await cache.set("greeting", "hello", ttl=60)
value = await cache.get("greeting")
print(value.unwrap()) # "hello"
if __name__ == "__main__":
import asyncio
asyncio.run(main())
Configuration
Zero-config usage: Call
CacheModule.configure()with no arguments; backends are then loaded from thecache:section ofapplication.yaml. UseCacheModule.stub()(in-memory) in tests.
Option 1 — YAML file
# application.yaml
cache:
enabled: true
backends:
- name: redis
type: redis
default: true
redis_url: "redis://localhost:6379/0"
default_ttl: 300
service:
enable_protection: true
Option 2 — Profiles + Environment Variables (recommended)
export QK_CACHE__ENABLED=true
export QK_CACHE__BACKENDS__0__TYPE=redis
export QK_CACHE__BACKENDS__0__REDIS_URL=redis://localhost:6379/0
Option 3 — Python
from quadkit.cache import CacheModule, CacheConfig
from quadkit.cache.config import CacheBackendConfig
from quadkit.cache.types import BackendType
CacheModule.configure(
CacheConfig(
backends=[
CacheBackendConfig(
name="redis",
type=BackendType.REDIS,
default=True,
redis_url="redis://localhost:6379/0",
)
]
)
)
Config reference
| Field | Default | Env var | Description |
|---|---|---|---|
enabled |
True |
QK_CACHE__ENABLED |
Enable the cache module |
backends[].name |
— | QK_CACHE__BACKENDS__0__NAME |
Unique backend name |
backends[].type |
— | QK_CACHE__BACKENDS__0__TYPE |
Backend type: redis, memory, memcached |
backends[].redis_url |
— | QK_CACHE__BACKENDS__0__REDIS_URL |
Redis connection URL |
backends[].default_ttl |
null |
QK_CACHE__BACKENDS__0__DEFAULT_TTL |
Default TTL in seconds |
service.enable_protection |
True |
QK_CACHE__SERVICE__ENABLE_PROTECTION |
Stampede protection |
service.circuit_breaker_enabled |
False |
QK_CACHE__SERVICE__CIRCUIT_BREAKER_ENABLED |
Circuit breaker on backend failures |
Module Factory Methods
| Method | Description |
|---|---|
CacheModule.configure(...) |
Configure with explicit CacheConfig |
CacheModule.stub() |
In-memory backend for unit testing |
Key Features
- Multi-backend — Redis, in-memory, and Memcached with a unified protocol
- Stampede protection — Distributed lock on cold reads prevents thundering herd
- Circuit breaker — Opens on repeated backend failures, falls through to origin
@cacheabledecorator — Cache-aside with automatic key generation and Result support- Domain model serialization — Type-tagged JSON envelope preserves type identity round-trip
- Production security — Blocks insecure Redis passwords when QK_ENV=production
Testing
from quadkit.cache import CacheService
async with Application.boot(modules=[CacheModule.stub()]) as app:
cache = await app.container.resolve(CacheService)
await cache.set("key", "value", ttl=60)
assert await cache.get("key") == "value"
Key Source Files
| File | What it contains |
|---|---|
src/quadkit/cache/module.py |
CacheModule with configure() and stub() |
src/quadkit/cache/config.py |
CacheConfig, CacheBackendConfig, CacheServiceConfig |
src/quadkit/cache/di/provider.py |
CacheProvider boot and registration |
src/quadkit/cache/decorators.py |
@cacheable decorator |
src/quadkit/cache/backends/ |
Redis, in-memory, and Memcached implementations |
Metadata
Release files for quadkit-cache 0.0.45
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| quadkit_cache-0.0.45.tar.gz | 176.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| quadkit_cache-0.0.45-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 324.6 kB
Release files / quadkit_cache-0.0.45.tar.gz
| Download URL | quadkit_cache-0.0.45.tar.gz |
|---|---|
| Size | 176.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a8727ead4c937ab1826b025a6eb79c307a8799b99475bc45120d20a088fa7e3c
|
|
BLAKE2b-256 checksum How to use checksums |
1427c89853ff26e879aa45abf977ce1c0ad47028cbee2f4e51447d50286e59a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / quadkit_cache-0.0.45-py3-none-any.whl
| Download URL | quadkit_cache-0.0.45-py3-none-any.whl |
|---|---|
| Size | 147.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
af4e4240b2264f0546606f1b6f52b1ffac2447938e287b740a06b39b3d589ef0
|
|
BLAKE2b-256 checksum How to use checksums |
df738b5b8a9fbaeca7d59679a1e1fd67000ca0bce6ee71759738e8bb66657d7a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for quadkit-cache 0.0.45
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.