use of com.squareup.okhttp.Cache in project nmid-headline by miao1007.
the class RetrofitUtils method getCachedAdapter.
public static Retrofit getCachedAdapter(String endpoint) {
Cache cache = null;
OkHttpClient okHttpClient = null;
Retrofit adapter;
try {
File cacheDir = new File(GlobalContext.getInstance().getCacheDir().getPath(), "pictures.json");
cache = new Cache(cacheDir, 10 * 1024 * 1024);
okHttpClient = new OkHttpClient();
okHttpClient.setCache(cache);
} catch (Exception e) {
e.printStackTrace();
}
adapter = new Retrofit.Builder().baseUrl(endpoint).addConverterFactory(GsonConverterFactory.create()).client(okHttpClient).build();
return adapter;
}
use of com.squareup.okhttp.Cache in project sbt-android by scala-android.
the class DebugView method setupOkHttpCacheSection.
private void setupOkHttpCacheSection() {
// Shares the cache with apiClient, so no need to check both.
Cache cache = client.getCache();
okHttpCacheMaxSizeView.setText(getSizeString(cache.getMaxSize()));
refreshOkHttpCacheStats();
}
use of com.squareup.okhttp.Cache in project sbt-android by scala-android.
the class DataModule method createOkHttpClient.
static OkHttpClient createOkHttpClient(Application app) {
OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(10, SECONDS);
client.setReadTimeout(10, SECONDS);
client.setWriteTimeout(10, SECONDS);
// Install an HTTP cache in the application cache directory.
File cacheDir = new File(app.getCacheDir(), "http");
Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE);
client.setCache(cache);
return client;
}
use of com.squareup.okhttp.Cache in project markdown-doclet by Abnaxos.
the class GithubAccessor method createCachedHttpConnector.
private OkHttpConnector createCachedHttpConnector() {
final File cacheDirectory = getCacheDirectory();
final Cache cache = new Cache(cacheDirectory, this.cacheSize);
return new OkHttpConnector(new OkUrlFactory(new OkHttpClient().setCache(cache)));
}
use of com.squareup.okhttp.Cache in project remusic by aa112901.
the class RestServiceFactory method create.
public static <T> T create(final Context context, String baseUrl, Class<T> clazz) {
final OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setCache(new Cache(context.getApplicationContext().getCacheDir(), CACHE_SIZE));
okHttpClient.setConnectTimeout(40, TimeUnit.SECONDS);
RequestInterceptor interceptor = new RequestInterceptor() {
@Override
public void intercept(RequestFacade request) {
// 7-days cache
request.addHeader("Cache-Control", String.format("max-age=%d,max-stale=%d", Integer.valueOf(60 * 60 * 24 * 7), Integer.valueOf(31536000)));
request.addHeader("Connection", "keep-alive");
}
};
RestAdapter.Builder builder = new RestAdapter.Builder().setEndpoint(baseUrl).setRequestInterceptor(interceptor).setClient(new OkClient(okHttpClient));
return builder.build().create(clazz);
}
Aggregations