dehydrate static method
Map<String, dynamic>
dehydrate({
- bool shouldDehydrate(
- QueryCacheEntry entry
- dynamic serialize(
- dynamic data,
- List key
Serializes the current request scope's cache into a plain, JSON-encodable Map.
By default includes only the current request's intended state (currentScope) — never another concurrent request's entries. This is the fix for cross-request dehydration leakage: call dehydrate inside withRequestScope / runWithScope after rendering.
Pass shouldDehydrate to filter which entries are included (e.g. to exclude
private session queries or other user data). By default, all non-expired entries
in the current scope are included.
Request-scoped SSR Example (recommended migration from static use)
final response = await BloomData.withRequestScope((scope) async {
// Private per-request data — isolated from concurrent requests.
BloomData.setQueryData(['user', 'current'], (_) => alice);
final html = renderToHtml(page());
final dehydrated = BloomData.dehydrate();
return '$html${BloomData.dehydrateToScriptTag(state: dehydrated)}';
});
See also:
- hydrate, to restore dehydrated state on the client.
- dehydrateToScriptTag, to serialize and format as a safe HTML script tag.
- hydrateFromJson, to restore cache from a JSON string.
Implementation
static Map<String, dynamic> dehydrate({
bool Function(QueryCacheEntry<dynamic> entry)? shouldDehydrate,
dynamic Function(dynamic data, List<dynamic> key)? serialize,
}) =>
currentScope.dehydrate(
shouldDehydrate: shouldDehydrate,
serialize: serialize,
);