worker8 / Pixels

Pixels is an Android app that brings you the beautiful and interesting pictures from Reddit
24 stars 3 forks source link

Add Room db as cache #14

Open worker8 opened 5 years ago

worker8 commented 5 years ago

After having comments and login, there will be data consistency issue. For example, upvoting in Comment View doesn't update the view in Home Feed View. By introducing Room, and by using Rx subscribing to the same Room item, the view will be updated automatically. Otherwise, we need to use some sort of EventBus which can be abused if not used properly.

Besides, Room can also serve as an offline cache. This is by no means a full blown offline support, it will simply show the last known data when offline. But mainly Room should be used as the cache to keep data consistency across the app.

Reddit data model comes with a unique id, that can be used as the primary key.

Migration strategy should be set to drop everything to prevent crash during schema change, since this is only for caching, we don't need to perform migration.