/** Sets the response cache to be used to read and write cached responses. */ public static void setResponseCache(OkUrlFactory okUrlFactory, ResponseCache responseCache) { OkHttpClient.Builder builder = okUrlFactory.client().newBuilder(); if (responseCache instanceof OkCacheContainer) { // Avoid adding layers of wrappers. Rather than wrap the ResponseCache in yet another layer to // make the ResponseCache look like an InternalCache, we can unwrap the Cache instead. // This means that Cache stats will be correctly updated. OkCacheContainer okCacheContainer = (OkCacheContainer) responseCache; builder.cache(okCacheContainer.getCache()); } else { builder.setInternalCache(responseCache != null ? new CacheAdapter(responseCache) : null); } okUrlFactory.setClient(builder.build()); } }
@Override public Response get(Request request) throws IOException { CacheResponse javaResponse = getJavaCachedResponse(request); if (javaResponse == null) { return null; } return JavaApiConverter.createOkResponseForCacheGet(request, javaResponse); }
@Override public Response get(Request request) throws IOException { CacheResponse javaResponse = getJavaCachedResponse(request); if (javaResponse == null) { return null; } return JavaApiConverter.createOkResponseForCacheGet(request, javaResponse); }
/** Sets the response cache to be used to read and write cached responses. */ public static void setResponseCache(OkUrlFactory okUrlFactory, ResponseCache responseCache) { OkHttpClient.Builder builder = okUrlFactory.client().newBuilder(); if (responseCache instanceof OkCacheContainer) { // Avoid adding layers of wrappers. Rather than wrap the ResponseCache in yet another layer to // make the ResponseCache look like an InternalCache, we can unwrap the Cache instead. // This means that Cache stats will be correctly updated. OkCacheContainer okCacheContainer = (OkCacheContainer) responseCache; builder.cache(okCacheContainer.getCache()); } else { builder.setInternalCache(responseCache != null ? new CacheAdapter(responseCache) : null); } okUrlFactory.setClient(builder.build()); } }