updateCache<T> method
Update cache for a query
Implementation
void updateCache<T>(String queryKey, T data, DateTime timestamp) {
final query = _queries[queryKey];
// Allow caching even without a query instance (e.g. prefetch)
// Default to 5 minutes if no query/config available
final cacheTime = query?.config.cacheTime ?? const Duration(minutes: 5);
_setCacheEntry(queryKey, data, timestamp, cacheTime);
// Persist if enabled
if (query != null) {
// 1. Notify active query instance to update UI (Optimistic Updates / Prefetch)
// Use dynamic dispatch to handle generic type erasure safely
try {
(query as dynamic).setData(data);
} catch (e) {
ZenLogger.logWarning(
'Failed to propagate cache update to query $queryKey: $e',
);
}
// 2. Persist
if (query.config.persist) {
_persistQuery(
queryKey, data, timestamp, query.config as ZenQueryConfig<T>);
}
}
}