File cacheDir = new File(System.getProperty("java.io.tmpdir"), "okhttp-cache"); cache = new HttpResponseCache(cacheDir, 10L * 1024 * 1024); okHttpClient = new OkHttpClient(); okHttpClient.setResponseCache(cache);
// Obtain the external cache directory File cacheDir = context.getExternalCacheDir(); if (cacheDir == null) { // Fall back to using the internal cache directory cacheDir = context().getCacheDir(); } // Create a response cache using the cache directory and size restriction HttpResponseCache responseCache = new HttpResponseCache( cacheDir, 10 * 1024 * 1024); // Prepare OkHttp httpClient = new OkHttpClient(); httpClient.setResponseCache(responseCache); // Build Picasso with this custom Downloader new Picasso.Builder(getContext()) .downloader(new OkHttpDownloader(httpClient)) .build();
File httpCacheDirectory = new File(application.getApplicationContext() .getCacheDir().getAbsolutePath(), "HttpCache"); HttpResponseCache httpResponseCache = null; try { httpResponseCache = new HttpResponseCache(httpCacheDirectory, 10 * 1024); } catch (IOException e) { Log.e(getClass().getSimpleName(), "Could not create http cache", e); } OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setResponseCache(httpResponseCache); builder.setClient(new OkClient(okHttpClient));
// Create an HTTP client that uses a cache on the file system. Android applications should use // their Context to get a cache directory. OkHttpClient okHttpClient = new OkHttpClient(); File cacheDir = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); HttpResponseCache cache = new HttpResponseCache(cacheDir, 1024); okHttpClient.setResponseCache(cache);