Search in sources :

Example 1 with CacheInterceptor

use of app.main.wangliwei.enablehands.http.interceptor.CacheInterceptor in project EnableHands by LeviWGG.

the class ServiceFactory method getOkhttpClient.

public OkHttpClient getOkhttpClient() {
    OkHttpClient.Builder builder = new OkHttpClient().newBuilder();
    File cachefile = new File(MyApplication.getMyContext().getExternalCacheDir(), "");
    Cache cache = new Cache(cachefile, 1024 * 1024 * 30);
    builder.cache(cache);
    HttpLogInterceptor httpLogInterceptor = new HttpLogInterceptor();
    builder.addInterceptor(httpLogInterceptor);
    CacheInterceptor cacheInterceptor = new CacheInterceptor();
    builder.addInterceptor(cacheInterceptor);
    builder.readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
    builder.writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
    builder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
    return builder.build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) HttpLogInterceptor(app.main.wangliwei.enablehands.http.interceptor.HttpLogInterceptor) File(java.io.File) CacheInterceptor(app.main.wangliwei.enablehands.http.interceptor.CacheInterceptor) Cache(okhttp3.Cache)

Aggregations

CacheInterceptor (app.main.wangliwei.enablehands.http.interceptor.CacheInterceptor)1 HttpLogInterceptor (app.main.wangliwei.enablehands.http.interceptor.HttpLogInterceptor)1 File (java.io.File)1 Cache (okhttp3.Cache)1 OkHttpClient (okhttp3.OkHttpClient)1