invalidateQueries static method
Invalidates all cached queries matching keyPrefix and notifies active BloomQuery subscribers.
Sets isStale = true on matching cache entries and triggers invalidation streams, causing
active enabled BloomQuery instances to automatically refetch in the background.
An empty prefix [] matches and invalidates all queries in the cache.
// Invalidate all tasks
BloomData.invalidateQueries(['tasks']);
// Invalidate a specific task
BloomData.invalidateQueries(['tasks', 42]);
Implementation
static void invalidateQueries(List<dynamic> keyPrefix) {
final prefixStr = normalizeKey(keyPrefix);
final matchingKeys = <String>{};
for (final entry in _cache.values) {
if (_matchesKey(entry.key, keyPrefix)) {
entry.isStale = true;
matchingKeys.add(normalizeKey(entry.key));
}
}
for (final keyStr in _invalidationControllers.keys) {
if (prefixStr.isEmpty || keyStr == prefixStr || keyStr.startsWith('$prefixStr:')) {
matchingKeys.add(keyStr);
}
}
for (final keyStr in matchingKeys) {
_invalidationControllers[keyStr]?.add(null);
}
}