I am creating an Android application (my first) that uses the REST API. I am using a background job to retrieve content, and I plan on using a GET request with the from_id parameter to get more content. Of course, everything that is extracted from the API is stored in SQLite db (I use greendao), and the application uses only the data that is already present there to be fast.
So the question is: what happens if this record is updated on the server? If the records that were once read are cached, why does the application notice that there are changes in synchronization? What strategies are feasible solutions?
Thanks.
EDIT:
As Satish P points out in his answer, client-server communication is handled using ETag (and I have to add the ability to use If-Modified-Since).
But my main problem is how to mix this with the user interface of the application. In this example:
- A list of items that have been retrieved from the REST service but from the client side is read from the local database to make the application more responsive.
- The user clicks on one of these items and a detailed view is displayed. Again, data is being downloaded from the local database. I assume that at this point a GET request is being requested for a particular record with either ETag headers or with-Since modification.
- It happens that the server returns a modified record, so the local data changes, so now you need to update everything that the user sees.
Problem: If the detailed view is already populated because the local database was read when a remote query is returned, how can I update the view? I do not think that only replacing the current data with more recent is acceptable, the user will see a change in blue.
source share