-1

I want to use network-bound resources meaning room caching with paging 3. If someone has done it please post your answer thanks.

1 Answers1

1

The NetworkBoundResource from architecture-components-samples is just a helper class wrapping access to a resource behind network + db cache. The canonical way to achieve this type of layered data in Paging is using RemoteMediator, which you can pass into Pager's constructor.

RemoteMediator essentially acts as a callback which fires when PagingSource runs out of data to load from the DB, where you can then make a network fetch, write the new items into the DB and invalidate to get Paging to pick up the new items. This seems really roundabout, but it assures that you have a single source of truth, so all of items displayed and loaded in your app are based on what's in the DB.

dlam
  • 3,547
  • 17
  • 20
  • No problem - there is a great guide here: https://developer.android.com/topic/libraries/architecture/paging/v3-network-db in case you need some more help with the implementation. – dlam Sep 22 '21 at 18:04
  • Yes, I have checked that. Actually, I was searching with Network Bound Resources. But the thing which worked for me was actually with Remote Mediator. Thank again. – Momin Tahir Sep 23 '21 at 12:35