1

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.

Community
  • 1
  • 1
wendigo
  • 1,973
  • 2
  • 17
  • 21
  • 2
    Picasso relies on the HTTP layer to cache the images. If the HTTP headers do not allow caching, or the cache time has expired, disc caching won't work. – nhaarman May 13 '14 at 10:01
  • Thanks for the answer, but I don't find where set the cache header up in my code. Could you guide me, please? Thanks again. – wendigo May 13 '14 at 13:58
  • 2
    The cache header is returned by the server, and, unless you control the server, you cannot change that. – nhaarman May 13 '14 at 14:00
  • Check my previous answer here, hope it help you: [http://stackoverflow.com/questions/22016382/invalidate-cache-in-picasso/29812708#29812708][1] [1]: http://stackoverflow.com/questions/22016382/invalidate-cache-in-picasso/29812708#29812708 – João M Apr 23 '15 at 02:54

0 Answers0