BloomData class
Global query cache manager and request deduplicator for Bloom JS Native applications.
BloomData provides a centralized, pure-Dart memory cache for asynchronous queries:
- Key Normalization: Deterministically serializes complex structured keys (Strings, Lists, Maps) via normalizeKey.
- Request Deduplication: Collapses concurrent identical requests into a single in-flight
Futurevia deduplicate. - Cache Invalidation: Notifies active BloomQuery instances via invalidateQueries using prefix matching.
- Direct Manipulation: Allows optimistic cache writing via setQueryData and direct inspection via getQueryData.
- SSR Dehydration & Hydration: Serializes cache snapshots to JSON via dehydrate or dehydrateToScriptTag, and restores them on the client via hydrate or hydrateFromJson with zero redundant fetches.
SSR & Browser Compatibility
Pure Dart with zero Flutter or DOM dependencies. In SSR environments, BloomData can be pre-populated with server data before rendering or cleared between requests via clear.
Example
// Manually prime or update the cache
BloomData.setQueryData<User>(['user', 123], (old) => updatedUser);
// Invalidate all queries under the 'user' prefix
BloomData.invalidateQueries(['user']);
See also:
- BloomQuery, the reactive query coordinator that reads from and populates BloomData.
- BloomInfiniteQuery, for paginated and cursor-based infinite queries.
- BloomMutation, for executing mutations that invalidate or optimistically update BloomData.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
clear(
) → void - Clears all cached query entries, active in-flight request deduplication trackers, and invalidation controllers.
-
deduplicate<
T> (List key, Future< T> fetcher()) → Future<T> -
Deduplicates concurrent asynchronous requests sharing the same cache
key. -
dehydrate(
{bool shouldDehydrate(QueryCacheEntry entry)?, dynamic serialize(dynamic data, List key)?}) → Map< String, dynamic> - Serializes the current BloomData cache into a plain, JSON-encodable Map.
-
dehydrateToScriptTag(
{Map< String, dynamic> ? state, String id = '__BLOOM_DATA__', bool shouldDehydrate(QueryCacheEntry entry)?, dynamic serialize(dynamic data, List key)?}) → String -
Serializes cache state into an HTML
<script type="application/json">tag string. -
getEntry<
T> (List key) → QueryCacheEntry< T> ? -
Retrieves the raw QueryCacheEntry for
key, returningnullif missing or expired. -
getQueryData<
T> (List key) → T? -
Retrieves non-expired cached query data for
key, or returnsnullif absent or expired. -
hydrate(
Map< String, dynamic> dehydratedState, {dynamic deserialize(dynamic data, List key)?}) → void -
Restores cache records from a
dehydratedStateMap into the BloomData cache. -
hydrateFromJson(
String jsonString, {dynamic deserialize(dynamic data, List key)?}) → void - Parses a serialized JSON string and restores the cache entries into BloomData.
-
invalidateQueries(
List keyPrefix) → void -
Invalidates all cached queries matching
keyPrefixand notifies active BloomQuery subscribers. -
normalizeKey(
List key) → String - Converts a structured key list into a normalized, canonical string key.
-
onInvalidated(
List key) → Stream< void> -
Returns a broadcast Stream that emits whenever queries matching
keyare invalidated. -
putEntry<
T> (QueryCacheEntry< T> entry) → void - Directly inserts or overwrites a QueryCacheEntry in the cache.
-
setQueryData<
T> (List key, T updater(T? oldData)) → void -
Directly updates cached query data for
keyusing a transformationupdatercallback.