Skip to content

Instantly share code, notes, and snippets.

@julianfalcionelli
Last active November 29, 2017 20:01
Show Gist options
  • Save julianfalcionelli/1989b1ef5bdd837b85e97beffaa5f93e to your computer and use it in GitHub Desktop.
Save julianfalcionelli/1989b1ef5bdd837b85e97beffaa5f93e to your computer and use it in GitHub Desktop.
Using Retrofit with Cache
//-------
private ExampleNetwork mExampleNetwork;
private void getDetails(String id) {
mExampleNetwork.getCachedDetails(id) // From Cache
.doFinally(() -> {
mExampleNetwork
.getDetails(id) // From Network
.subscribe(details -> onDetailsReceived(details), this::onError);
})
.subscribe(details -> onDetailsReceived(details), this::onError);
}
private void onDetailsReceived(Details details) {
if (mDetails == null || !mDetails.equals(details)) { // Implement equals with your criteria
mDetails = details;
updateUI();
}
}
//-------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment