Tabnine Logo
OkHttpClient$Builder.cache
Code IndexAdd Tabnine to your IDE (free)

How to use
cache
method
in
okhttp3.OkHttpClient$Builder

Best Java code snippets using okhttp3.OkHttpClient$Builder.cache (Showing top 20 results out of 1,242)

origin: square/okhttp

public CacheResponse(File cacheDirectory) throws Exception {
 int cacheSize = 10 * 1024 * 1024; // 10 MiB
 Cache cache = new Cache(cacheDirectory, cacheSize);
 client = new OkHttpClient.Builder()
   .cache(cache)
   .build();
}
origin: square/okhttp

 public static void main(String[] args) throws IOException {
  if (args.length != 2) {
   System.out.println("Usage: Crawler <cache dir> <root>");
   return;
  }

  int threadCount = 20;
  long cacheByteCount = 1024L * 1024L * 100L;

  Cache cache = new Cache(new File(args[0]), cacheByteCount);
  OkHttpClient client = new OkHttpClient.Builder()
    .cache(cache)
    .build();

  Crawler crawler = new Crawler(client);
  crawler.queue.add(HttpUrl.get(args[1]));
  crawler.parallelDrainQueue(threadCount);
 }
}
origin: amitshekhariitbhu/Fast-Android-Networking

public static void setClientWithCache(Context context) {
  sHttpClient = new OkHttpClient().newBuilder()
      .cache(Utils.getCache(context, ANConstants.MAX_CACHE_SIZE, ANConstants.CACHE_DIR_NAME))
      .connectTimeout(60, TimeUnit.SECONDS)
      .readTimeout(60, TimeUnit.SECONDS)
      .writeTimeout(60, TimeUnit.SECONDS)
      .build();
}
origin: amitshekhariitbhu/Fast-Android-Networking

.getOkHttpClient()
.newBuilder()
.cache(InternalNetworking.sHttpClient.cache())
.build()
.newCall(okHttpRequest));
origin: amitshekhariitbhu/Fast-Android-Networking

.getOkHttpClient()
.newBuilder()
.cache(InternalNetworking.sHttpClient.cache())
.build()
.newCall(okHttpRequest));
origin: iMeiji/Toutiao

.cache(cache)
.addInterceptor(cacheControlInterceptor)
.connectTimeout(10, TimeUnit.SECONDS)
origin: jaydenxiao2016/AndroidFire

.addInterceptor(headerInterceptor)
.addInterceptor(logInterceptor)
.cache(cache)
.build();
origin: amitshekhariitbhu/Fast-Android-Networking

request.setCall(request.getOkHttpClient()
    .newBuilder()
    .cache(sHttpClient.cache())
    .build()
    .newCall(okHttpRequest));
origin: amitshekhariitbhu/Fast-Android-Networking

.getOkHttpClient()
.newBuilder()
.cache(InternalNetworking.sHttpClient.cache())
.addNetworkInterceptor(new Interceptor() {
  @Override
origin: amitshekhariitbhu/Fast-Android-Networking

.getOkHttpClient()
.newBuilder()
.cache(InternalNetworking.sHttpClient.cache())
.addNetworkInterceptor(new Interceptor() {
  @Override
origin: Rukey7/MvpApp

/**
 * 初始化网络通信服务
 */
public static void init() {
  // 指定缓存路径,缓存大小100Mb
  Cache cache = new Cache(new File(AndroidApplication.getContext().getCacheDir(), "HttpCache"),
      1024 * 1024 * 100);
  OkHttpClient okHttpClient = new OkHttpClient.Builder().cache(cache)
      .retryOnConnectionFailure(true)
      .addInterceptor(sLoggingInterceptor)
      .addInterceptor(sRewriteCacheControlInterceptor)
      .addNetworkInterceptor(sRewriteCacheControlInterceptor)
      .connectTimeout(10, TimeUnit.SECONDS)
      .build();
  Retrofit retrofit = new Retrofit.Builder()
      .client(okHttpClient)
      .addConverterFactory(GsonConverterFactory.create())
      .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
      .baseUrl(NEWS_HOST)
      .build();
  sNewsService = retrofit.create(INewsApi.class);
  retrofit = new Retrofit.Builder()
      .client(okHttpClient)
      .addConverterFactory(GsonConverterFactory.create())
      .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
      .baseUrl(WELFARE_HOST)
      .build();
  sWelfareService = retrofit.create(IWelfareApi.class);
}
origin: north2016/T-MVP

private Api() {
  HttpLoggingInterceptor logInterceptor = new HttpLoggingInterceptor();
  logInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
  File cacheFile = new File(App.getAppContext().getCacheDir(), "cache");
  Cache cache = new Cache(cacheFile, 1024 * 1024 * 100); //100Mb
  OkHttpClient okHttpClient = new OkHttpClient.Builder()
      .readTimeout(7676, TimeUnit.MILLISECONDS)
      .connectTimeout(7676, TimeUnit.MILLISECONDS)
      .addInterceptor(headInterceptor)
      .addInterceptor(logInterceptor)
      .addNetworkInterceptor(new HttpCacheInterceptor())
      .cache(cache)
      .build();
  Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").serializeNulls().create();
  retrofit = new Retrofit.Builder()
      .client(okHttpClient)
      .addConverterFactory(GsonConverterFactory.create(gson))
      .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
      .baseUrl(C.BASE_URL)
      .build();
  service = retrofit.create(ApiService.class);
}
origin: HotBitmapGG/bilibili-android-client

/**
 * 初始化OKHttpClient,设置缓存,设置超时时间,设置打印日志,设置UA拦截器
 */
private static void initOkHttpClient() {
  HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
  interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
  if (mOkHttpClient == null) {
    synchronized (RetrofitHelper.class) {
      if (mOkHttpClient == null) {
        //设置Http缓存
        Cache cache = new Cache(new File(BilibiliApp.getInstance().getCacheDir(), "HttpCache"), 1024 * 1024 * 10);
        mOkHttpClient = new OkHttpClient.Builder()
            .cache(cache)
            .addInterceptor(interceptor)
            .addNetworkInterceptor(new CacheInterceptor())
            .addNetworkInterceptor(new StethoInterceptor())
            .retryOnConnectionFailure(true)
            .connectTimeout(30, TimeUnit.SECONDS)
            .writeTimeout(20, TimeUnit.SECONDS)
            .readTimeout(20, TimeUnit.SECONDS)
            .addInterceptor(new UserAgentInterceptor())
            .build();
      }
    }
  }
}
origin: GitLqr/LQRWeChat

  public BaseApiRetrofit() {
    /*================== common ==================*/

    // Log信息拦截器
//        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
//        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.NONE);//这里可以选择拦截级别

    //cache
    File httpCacheDir = new File(MyApp.getContext().getCacheDir(), "response");
    int cacheSize = 10 * 1024 * 1024;// 10 MiB
    Cache cache = new Cache(httpCacheDir, cacheSize);

    //cookie
    ClearableCookieJar cookieJar =
        new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(MyApp.getContext()));

    //OkHttpClient
    mClient = new OkHttpClient.Builder()
        .addInterceptor(REWRITE_HEADER_CONTROL_INTERCEPTOR)
        .addInterceptor(REWRITE_CACHE_CONTROL_INTERCEPTOR)
        .addInterceptor(new LoggingInterceptor())
//                .addInterceptor(loggingInterceptor)//设置 Debug Log 模式
        .cache(cache)
        .cookieJar(cookieJar)
        .build();
  }

origin: amitshekhariitbhu/Fast-Android-Networking

/**
 * Initializes AndroidNetworking with the specified config.
 *
 * @param context      The context
 * @param okHttpClient The okHttpClient
 */
public static void initialize(Context context, OkHttpClient okHttpClient) {
  if (okHttpClient != null && okHttpClient.cache() == null) {
    okHttpClient = okHttpClient
        .newBuilder()
        .cache(Utils.getCache(context.getApplicationContext(),
            ANConstants.MAX_CACHE_SIZE, ANConstants.CACHE_DIR_NAME))
        .build();
  }
  InternalNetworking.setClient(okHttpClient);
  ANRequestQueue.initialize();
  ANImageLoader.initialize();
}
origin: square/okhttp

clientBuilder.cache(null);
origin: gotev/android-upload-service

public OkHttpStack() {
  mClient = new OkHttpClient.Builder()
      .followRedirects(true)
      .followSslRedirects(true)
      .retryOnConnectionFailure(true)
      .connectTimeout(15, TimeUnit.SECONDS)
      .writeTimeout(30, TimeUnit.SECONDS)
      .readTimeout(30, TimeUnit.SECONDS)
      .cache(null)
      .build();
}
origin: square/picasso

 /** Create the {@link Picasso} instance. */
 @NonNull
 public Picasso build() {
  Context context = this.context;
  okhttp3.Cache unsharedCache = null;
  if (callFactory == null) {
   File cacheDir = createDefaultCacheDir(context);
   long maxSize = calculateDiskCacheSize(cacheDir);
   unsharedCache = new okhttp3.Cache(cacheDir, maxSize);
   callFactory = new OkHttpClient.Builder()
     .cache(unsharedCache)
     .build();
  }
  if (cache == null) {
   cache = new PlatformLruCache(Utils.calculateMemoryCacheSize(context));
  }
  if (service == null) {
   service = new PicassoExecutorService(new PicassoThreadFactory());
  }
  Stats stats = new Stats(cache);
  Dispatcher dispatcher = new Dispatcher(context, service, HANDLER, cache, stats);
  return new Picasso(context, dispatcher, callFactory, unsharedCache, cache, listener,
    requestTransformers, requestHandlers, stats, defaultBitmapConfig, indicatorsEnabled,
    loggingEnabled);
 }
}
origin: square/okhttp

 /** 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());
 }
}
origin: square/okhttp

public RewriteResponseCacheControl(File cacheDirectory) throws Exception {
 Cache cache = new Cache(cacheDirectory, 1024 * 1024);
 cache.evictAll();
 client = new OkHttpClient.Builder()
   .cache(cache)
   .build();
}
okhttp3OkHttpClient$Buildercache

Javadoc

Sets the response cache to be used to read and write cached responses.

Popular methods of OkHttpClient$Builder

  • build
  • <init>
  • connectTimeout
    Sets the default connect timeout for new connections. A value of 0 means no timeout, otherwise value
  • addInterceptor
  • readTimeout
    Sets the default read timeout for new connections. A value of 0 means no timeout, otherwise values m
  • writeTimeout
    Sets the default write timeout for new connections. A value of 0 means no timeout, otherwise values
  • addNetworkInterceptor
  • sslSocketFactory
    Sets the socket factory and trust manager used to secure HTTPS connections. If unset, the system def
  • hostnameVerifier
    Sets the verifier used to confirm that response certificates apply to requested hostnames for HTTPS
  • retryOnConnectionFailure
    Configure this client to retry or not when a connectivity problem is encountered. By default, this c
  • cookieJar
    Sets the handler that can accept cookies from incoming HTTP responses and provides cookies to outgoi
  • proxy
    Sets the HTTP proxy that will be used by connections created by this client. This takes precedence o
  • cookieJar,
  • proxy,
  • followRedirects,
  • proxyAuthenticator,
  • connectionPool,
  • connectionSpecs,
  • authenticator,
  • followSslRedirects,
  • dispatcher

Popular in Java

  • Reactive rest calls using spring rest template
  • onCreateOptionsMenu (Activity)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • startActivity (Activity)
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • Socket (java.net)
    Provides a client-side TCP socket.
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Top 17 Free Sublime Text Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now