List of usage examples for com.squareup.okhttp Cache Cache
public Cache(File directory, long maxSize)
From source file:app.philm.in.network.PhilmTmdb.java
License:Apache License
@Override protected RestAdapter.Builder newRestAdapterBuilder() { RestAdapter.Builder b = super.newRestAdapterBuilder(); if (mCacheLocation != null) { OkHttpClient client = new OkHttpClient(); try {/*w w w. ja va 2 s . com*/ File cacheDir = new File(mCacheLocation, UUID.randomUUID().toString()); Cache cache = new Cache(cacheDir, 1024); client.setCache(cache); } catch (IOException e) { Log.e(TAG, "Could not use OkHttp Cache", e); } client.setConnectTimeout(Constants.CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); client.setReadTimeout(Constants.READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); b.setClient(new OkClient(client)); } return b; }
From source file:augsburg.se.alltagsguide.ServicesModule.java
License:Open Source License
@Singleton @Provides/*from w w w .ja v a2s . c o m*/ OkHttpClient okHttpClient(Context context, @Named("cacheDir") File cachedir) { Ln.d("okHttpClient is intialized."); int cacheSize = 50 * 1024 * 1024; // 50 MiB Cache cache = new Cache(cachedir, cacheSize); OkHttpClient client = new OkHttpClient(); client.setCache(cache); client.setConnectTimeout(10, TimeUnit.SECONDS); client.setWriteTimeout(10, TimeUnit.SECONDS); client.setReadTimeout(30, TimeUnit.SECONDS); return client; }
From source file:cat.ppicas.cleanarch.app.DefaultServiceContainer.java
License:Apache License
private Cache createOkHttpCache() { try {/*from w w w . j a v a 2 s . c o m*/ File directory = new File(mContext.getCacheDir(), "ok-http"); return new Cache(directory, 3000000); } catch (IOException e) { return null; } }
From source file:co.paralleluniverse.fibers.okhttp.CallTest.java
License:Open Source License
@Before public void setUp() throws Exception { client = new FiberOkHttpClient(); callback = new RecordingCallback(); logHandler = new TestLogHandler(); cache = new Cache(tempDir.getRoot(), Integer.MAX_VALUE); logger.addHandler(logHandler);//from w w w . j ava 2s . c o m }
From source file:com.adamg.materialtemplate.cloud.module.OkHttpModule.java
License:MIT License
/** * Creates a default OkHttp client with a disk cache of 10 MB * * @param ctx a reference to the Client's {@link Context} * @return the instance of the OkHttp Client used as the transport layer for API calls *//* ww w .ja v a2 s. com*/ static OkHttpClient createOkHttpClient(final Context ctx) { OkHttpClient client = new OkHttpClient(); // Install an HTTP cache in the application cache directory. try { final File cacheDir = new File(ctx.getCacheDir(), "https"); final Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE); client.setCache(cache); } catch (final IOException e) { // Log the error Log.e(TAG, "Unable to install disk cache." + Log.getStackTraceString(e)); } return client; }
From source file:com.animedetour.android.framework.dependencyinjection.module.ApplicationModule.java
License:Open Source License
@Provides @Singleton//from www . jav a 2s . c o m public Cache cache(Application application) { File cacheDir = new File(application.getCacheDir(), "http"); long cacheSize = 80 * 1024 * 1024; // 80MB return new Cache(cacheDir, cacheSize); }
From source file:com.anony.okhttp.sample.CacheResponse.java
License:Apache License
public CacheResponse(File cacheDirectory) throws Exception { int cacheSize = 10 * 1024 * 1024; // 10 MiB Cache cache = new Cache(cacheDirectory, cacheSize); client = new OkHttpClient(); client.setCache(cache);//w w w .java2s . com }
From source file:com.anony.okhttp.sample.RewriteResponseCacheControl.java
License:Apache License
public RewriteResponseCacheControl(File cacheDirectory) throws Exception { Cache cache = new Cache(cacheDirectory, 1024 * 1024); cache.evictAll();// w w w. j av a 2 s .co m client = new OkHttpClient(); client.setCache(cache); }
From source file:com.apothesource.pillfill.network.PFNetworkManager.java
License:Open Source License
private static Cache getDefaultCache() { try {/*from www .j ava 2 s. c om*/ return new Cache(Files.createTempDirectory("networkCache").toFile(), DEFAULT_CACHE_SIZE); } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:com.arnaudpiroelle.marvel.api.rest.client.RetrofitHttpClient.java
License:Apache License
private static OkUrlFactory generateDefaultOkUrlFactory() { OkHttpClient client = new com.squareup.okhttp.OkHttpClient(); client.setConnectTimeout(CONNECT_TIMEOUT_SEC, TimeUnit.SECONDS); client.setReadTimeout(READ_TIMEOUT_SEC, TimeUnit.SECONDS); try {/*from w w w . j ava 2 s . co m*/ File cacheDir = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); Cache cache = new Cache(cacheDir, 1024); client.setCache(cache); } catch (IOException e) { e.printStackTrace(); } return new OkUrlFactory(client); }