I'm working on an application that consumes JSON feed from the backend. By default, an HTTP request will be fired every time when the user accesses the application while being connected to the Internet, and if there's no network the data should be loaded from cache. I'm using Retrofit for networking, and I see two ways to implement caching: either use an OkHttp client configured to support caching, or create an SQLite database to store data. The second option is familiar to me, therefore looks more reliable, however there's a lot of overhead related to this approach. I've never really used HTTP caching, and I'd like to know whether it's sufficient to just rely on it for offline data viewing?
You are right about SQLite, it is better approach which is to separate HTTP requests and access to actual data. Since it is feed, it is structured data. You can do following approach:
This way, you always have access to data even if there is no internet. You can trigger HTTP poll any good time and update DB. On update/change have observer of content data to trigger loader and update UI if that's shown currently to user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With