setQueriesData<T> method
Functionally update cached data for all queries matching filter.
updater receives the previous data and returns new data for each matching query.
Queries whose data type does not match T are safely skipped.
Implementation
void setQueriesData<T>(
ZenQueryFilter filter,
T Function(T? oldData) updater,
) {
final matchingKeys = getMatchingKeys(filter);
int updatedCount = 0;
for (final key in matchingKeys) {
final query = _queries[key];
if (query != null && query is! ZenQuery<T>) {
ZenLogger.logDebug(
'Skipping setQueriesData<$T> for "$key": query type is ${query.runtimeType}',
);
continue;
}
final entry = _cache[key];
if (entry != null && !entry.isExpired && entry.data is! T?) {
ZenLogger.logDebug(
'Skipping setQueriesData<$T> for "$key": cached type is ${entry.data.runtimeType}',
);
continue;
}
final oldData = getCachedData<T>(key);
final newData = updater(oldData);
updateCache(key, newData, DateTime.now());
updatedCount++;
}
ZenLogger.logDebug(
'Batch updated data for $updatedCount queries matching filter',
);
}