Skip to content

Ferry Cache-Based Pagination

Cache-Based Pagination

Use Ferry’s cache to serve already-fetched entities instantly. This replaces the StreamGroup approach.

The StreamGroup approach adds complexity: multiple streams, manual page tracking, merging logic, race conditions. Ferry’s cache-based approach is simpler.

@riverpod
class AttendeeListNotifier extends _$AttendeeListNotifier {
static const int _pageSize = 15;
int _currentTake = _pageSize;
@override
Stream<List<AttendeeModel>> build() {
_currentTake = _pageSize;
final repository = ref.watch(attendeeRepositoryProvider);
return repository.queryList(
skip: 0,
take: _currentTake,
);
}
void loadMore() {
_currentTake += _pageSize;
ref.invalidateSelf();
}
void filter({String? fullName}) {
_currentTake = _pageSize;
ref.invalidateSelf();
}
}
  1. First load: take: 15 fetches 15 items, caches them
  2. Load more: take: 30 - Ferry serves first 15 from cache, fetches next 15 from network
  3. Filter change: Fresh request with reset take

Each entity is cached by __typename:id, so Ferry reassembles lists efficiently.