Skip to content

Instantly share code, notes, and snippets.

@bamssong
Created September 26, 2015 17:41
Show Gist options
  • Select an option

  • Save bamssong/af0e705a6f100593755c to your computer and use it in GitHub Desktop.

Select an option

Save bamssong/af0e705a6f100593755c to your computer and use it in GitHub Desktop.
RestAdapter.Builder builder= new RestAdapter.Builder()
.setRequestInterceptor(new RequestInterceptor() {
@Override
public void intercept(RequestFacade request) {
request.addHeader("Accept", "application/json;versions=1");
if (MyApplicationUtils.isNetworkAvailable(context)) {
int maxAge = 60; // read from cache for 1 minute
request.addHeader("Cache-Control", "public, max-age=" + maxAge);
} else {
int maxStale = 60 * 60 * 24 * 28; // tolerate 4-weeks stale
request.addHeader("Cache-Control",
"public, only-if-cached, max-stale=" + maxStale);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment