Exemplo n.º 1
0
 /** Sets the response cache to be used to read and write cached responses. */
 public static void setResponseCache(OkUrlFactory okUrlFactory, ResponseCache responseCache) {
   OkHttpClient client = okUrlFactory.client();
   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;
     client.setCache(okCacheContainer.getCache());
   } else {
     client.setInternalCache(responseCache != null ? new CacheAdapter(responseCache) : null);
   }
 }