ピカソの画像をインターネットから読み込み、接続なしでディスクキャッシュから読み込みたいです。キャッシュは正常に書き込まれています (画像はキャッシュ ディレクトリにあります)。しかし、読んでいるとき、私はこのログを取得します:
Sending progress READING_FROM_CACHE
Cache content not available or expired or disabled
私のプロジェクトには、リクエスト用のレトロフィットとokhttpがあります。そして、この画像には次のCODEがロードされています:
// Obtain the cache directory
File cacheDir = getActivity().getCacheDir();
// Create a response cache using the cache directory and size restriction
HttpResponseCache responseCache = null;
try {
responseCache = new HttpResponseCache(
cacheDir,
10 * 1024 * 1024);
} catch (IOException e) {
e.printStackTrace();
}
// Prepare OkHttp
OkHttpClient httpClient = new OkHttpClient();
httpClient.setResponseCache(responseCache);
// Build Picasso with this custom Downloader
Picasso picasso = new Picasso.Builder(getActivity())
.downloader(new OkHttpDownloader(httpClient))
.build();
picasso.setDebugging(true);
picasso.with(getActivity())
.load(profilePicUrl) // url picture
.resize(180, 180)
.centerCrop()
.placeholder(R.drawable.ic_int_profile_no_photo)
.into(mProfilePic); //ImageView
その結果、接続がないと、画像は読み込まれませんが、画像は picasso のキャッシュ ディレクトリにあります (ログにはそのメッセージが表示されます)。
アイデア
Picasso のカスタム Download を使用する場合、レトロフィット リクエスト ヘッダーを変更する必要はないと思います (RequestInterceptor -> インターセプト)。多くの POST および GET リクエストがあり、そのままにしておきたいです。
私がチェックしたいくつかのリンク
picasso ライブラリで独自のディスク キャッシュを実装する方法 - Android?
https://github.com/square/picasso/issues/237
picasso のキャッシュメモリから画像を取得するには?
前もって感謝します。