質問

I'm using picasso library to load images for my app. But I don't how to implement my own disk (sdcard) caching with picasso library.

役に立ちましたか?

解決

Picasso uses the HTTP client for disk caching and if one is already configured it will use that instead of installing its own.

For the built-in UrlConnection the docs for installing a cache are here: https://developer.android.com/reference/android/net/http/HttpResponseCache.html

If you are using OkHttp then you just call setCache: http://square.github.io/okhttp/2.x/okhttp/com/squareup/okhttp/OkHttpClient.html#setCache-com.squareup.okhttp.Cache-

他のヒント

@Dax, to save files in custom cache directory using OkHttp, I would code something like this -

OkHttpClient okHttpClient = new OkHttpClient();
File customCacheDirectory = new File(Environment.getExternalStorageDirectory().getAbsoluteFile() + "/MyCache");
okHttpClient.setCache(new Cache(customCacheDirectory, Integer.MAX_VALUE));
OkHttpDownloader okHttpDownloader = new OkHttpDownloader(okHttpClient);
Picasso picasso = new Picasso.Builder(mainActivity).downloader(okHttpDownloader).build();
picasso.load(imageURL).into(viewHolder.image);

Hope this helps.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top