How To Use Room Database As A Cache
Solution 1:
your question explains exactly how you would use Room:
- fetch data from an api
- insert it into room database
- fetch it from room in my app
Room allows you to store your data locally and retrieve this data with various different threads, making use of something like Rxjava, it also allows you to observe onto any changes with LiveData, Room is definitely a decent option to consider for caching
BUT
Using Room is ONE of SEVERAL different implementations of caching, consider posting code or a specific scenario for better answers. Happy coding.
Edit:
A common approach to using Room (or any caching) would be to either load initial data from the database, display this to the user, perform an api call, update the cache and display this updated data from the api
OR
If the user does not have an internet connection, simply use what he has available in the cache as data. Again, all of this depends on your specific scenario.
Post a Comment for "How To Use Room Database As A Cache"