setItems method
Persists all items.
Implementation
@override
Future<WriteListResult<T>> setItems(
Iterable<T> items,
RequestDetails details,
) async {
if (items.isEmpty) {
await clearForRequest(details);
return WriteListSuccess<T>(items, details: details);
}
final itemIds = items.map<String>((item) => bindings.getId(item)!).toSet();
_log.finest('Caching $itemIds to ${details.cacheKey}');
await _requestCache.write(
details.cacheKey,
itemIds,
ttl: details.ttl ?? ttl,
);
if (details.pagination != null) {
final pageClusterCacheKeys =
await _paginatedRequestCache.read(
details.noPaginationCacheKey,
) ??
<CacheKey>{};
if (!pageClusterCacheKeys.contains(details.cacheKey)) {
pageClusterCacheKeys.add(details.cacheKey);
await _paginatedRequestCache.write(
details.noPaginationCacheKey,
pageClusterCacheKeys,
// Do not pass ttl here -- that is handled by [_requestCache]
// because paginated requests timeout individually, not as a cluster
);
}
}
// Now save the actual item payloads
await _itemsCache.multiWrite(
Map.fromEntries(
items.map<MapEntry<String, T>>(
(item) => MapEntry(bindings.getId(item)!, item),
),
),
ttl: details.ttl ?? ttl,
);
return WriteListSuccess<T>(items, details: details);
}