Cache requests using retrofit2 and okhttp3

Viewed 192

I am using retrofit2 to cash responses using cache interceptor

 @Override
public Response intercept(Chain chain) throws IOException {
    Response originalResponse = chain.proceed(chain.request());
    if (NetworkUtil.isConnected(context)) {
        return originalResponse.newBuilder()
                .header("Cache-Control", "public, max-age=" + MAX_AGE)
                .build();
    } else {
        return originalResponse.newBuilder()
                .header("Cache-Control", "public, only-if-cached, max-stale=" + MAX_STALE)
                .build();
    }
}

but i need to cache specific requests not all of it, how to do that?

1 Answers
Related