本文整理汇总了Java中okhttp3.internal.huc.CacheAdapter类的典型用法代码示例。如果您正苦于以下问题:Java CacheAdapter类的具体用法?Java CacheAdapter怎么用?Java CacheAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CacheAdapter类属于okhttp3.internal.huc包,在下文中一共展示了CacheAdapter类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setResponseCache
import okhttp3.internal.huc.CacheAdapter; //导入依赖的package包/类
/** 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());
}