Skip to content

Instantly share code, notes, and snippets.

@lmeadors
Created June 21, 2013 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmeadors/5834121 to your computer and use it in GitHub Desktop.
Save lmeadors/5834121 to your computer and use it in GitHub Desktop.
private BorrowedListMessage getResponse(boolean forceRefresh) {
final BorrowedListMessage response;
if (forceRefresh) {
// force is true - try the service
final BorrowedListMessage serviceResponse = borrowedService.getBorrowed(patron);
if (serviceResponse.getResponseStatus().equals(ResponseStatus.OK)) {
// service response is good - use it
response = serviceResponse;
} else {
// service response is bad - try the cached data
final BorrowedListMessage cachedResponse = state.getBorrowed(context);
if (null == cachedResponse) {
// cached data is bunk - use the failing service response
response = serviceResponse;
} else {
// cache is good - use it
response = cachedResponse;
}
}
} else {
// force is false - try the cached data
final BorrowedListMessage cachedResponse = state.getBorrowed(context);
if (null != cachedResponse) {
// cached data is good - use it
response = cachedResponse;
} else {
// cached data is bunk - use the service response, regardless of it's outcome
response = borrowedService.getBorrowed(patron);
}
}
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment