BloomQuery<T> class

A reactive asynchronous query with automatic caching, stale-while-revalidate, and deduplication.

Subscribes to global BloomData cache invalidation events and exposes reactive signals for data, status, error, isFetching, and isStale.

Example:

final userQuery = BloomQuery<User>(
  key: ['user', 42],
  fetch: () => api.fetchUser(42),
  staleTime: const Duration(minutes: 5),
);

print(userQuery.data.value?.name);

Constructors

BloomQuery({required List key, required QueryFetcher<T> fetch, Duration staleTime = const Duration(minutes: 5), Duration cacheTime = const Duration(minutes: 30), bool enabled = true, int retry = 2, Duration retryDelay = const Duration(milliseconds: 500)})
Creates a BloomQuery with cache key, fetcher, and configuration options.

Properties

cacheTime Duration
Maximum duration to keep cached data in memory before garbage collection.
final
data ReadonlySignal<T?>
Reactive signal containing the current data value T, or null.
no setter
enabled bool
Whether this query automatically fetches on initialization (defaults to true).
final
error ReadonlySignal<Object?>
Reactive signal containing the error object if the query failed, or null.
no setter
fetch QueryFetcher<T>
Asynchronous function that fetches fresh data from network or database.
final
hasData bool
Whether valid data is currently available in this query.
no setter
hashCode int
The hash code for this object.
no setterinherited
isError bool
Whether the query has failed with an error.
no setter
isFetching ReadonlySignal<bool>
Reactive signal indicating whether a network fetch is actively occurring in background.
no setter
isLoading bool
Whether the query is currently performing its initial loading fetch.
no setter
isStale ReadonlySignal<bool>
Reactive signal indicating whether the current data is considered stale.
no setter
isSuccess bool
Whether the query has resolved successfully with cached or fresh data.
no setter
key List
Unique cache key identifying this query.
final
retry int
Number of retry attempts on network/fetch failure (defaults to 2).
final
retryDelay Duration
Base delay duration between retry attempts (defaults to 500ms).
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
staleTime Duration
Duration after which cached data is considered stale and revalidated on access.
final
status ReadonlySignal<QueryStatus>
Reactive signal containing the current query status.
no setter

Methods

dispose() → void
Disposes this query instance, unregisters invalidation listeners, and releases cache slots.
invalidate() → void
Marks this query as invalidated and triggers an immediate background refetch.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
refetch() Future<T?>
Manually triggers a fresh background revalidation.
setData(T newData) → void
Overrides data directly in memory cache and notifies all active observers.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited