I want to load a picture with Picasso from internet, and without connectivity, from disk cache. The cache is writing fine (the picture is in the cache dir). But when reading I get this log:
Sending progress READING_FROM_CACHE
Cache content not available or expired or disabled
I have retrofit and okhttp in my project for requests. And this picture is loaded with this 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
The result is that without connectivity, the picture don't load, but the picture is in the cache dir of picasso (and the log shows that message).
Ideas
I think that if I use a custom Download for Picasso I don't must to modify my retrofit requests headers (RequestInterceptor -> intercept). I have many POST and GET request and I'd like leave them as are.
Some links that I have checked
How to implement my own disk cache with picasso library - Android?
https://github.com/square/picasso/issues/237
How to retrieve images from cache memory in picasso?
Thanks in advance.