refreshStreams method

Future<void> refreshStreams()

Refreshes all reactive streams by clearing caches and forcing streams to re-evaluate their data. This is useful when external state changes (like user switches) require all streams to refresh their data.

This method clears internal caches and forces reactive streams to emit fresh data on their next evaluation. For adapters with reactive streams, this ensures that streams show the most current data after state changes.

Implementation

Future<void> refreshStreams() async {
  _ensureInitialized();

  // Clear all caches to ensure fresh data
  clearCaches();

  // Emit a special refresh event that will be picked up by all streams
  // We use a special marker to indicate this is a refresh event
  _eventController.add(
    DataChangeEvent<T>(
      userId: '__REFRESH_STREAMS__', // Special marker for refresh
      data: null,
      changeType: ChangeType.updated,
      source: DataSource.local,
    ),
  );

  _logger.debug('Refreshed all streams for $T');
}