Ferry Cache-Based Pagination
Cache-Based Pagination
Use Ferry’s cache to serve already-fetched entities instantly. This replaces the StreamGroup approach.
Ferry Cache-Based Pagination
Section titled “Ferry Cache-Based Pagination”Why Not StreamGroup?
Section titled “Why Not StreamGroup?”The StreamGroup approach adds complexity: multiple streams, manual page tracking, merging logic, race conditions. Ferry’s cache-based approach is simpler.
Implementation
Section titled “Implementation”Notifier with Cache-Based Pagination
Section titled “Notifier with Cache-Based Pagination”@riverpodclass 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(); }}How Ferry Cache Makes This Work
Section titled “How Ferry Cache Makes This Work”- First load:
take: 15fetches 15 items, caches them - Load more:
take: 30- Ferry serves first 15 from cache, fetches next 15 from network - Filter change: Fresh request with reset
take
Each entity is cached by __typename:id, so Ferry reassembles lists efficiently.