/** 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 void shutdown() { try { factory.client().dispatcher().executorService().shutdown(); factory.client().dispatcher().executorService().awaitTermination(5, TimeUnit.MINUTES); // Evict all the connections factory.client().connectionPool().evictAll(); } catch (InterruptedException e) { // Oh well; we were only trying to aggressively shutdown } } }
/** 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()); } }