Search code examples
javaandroidpicasso

Picasso Image downloaded again for an ImageView with different dimensions?


I'm using Picasso in my application for loading image efficiently and is doing his job at the best.The issue is that, currently if i call Picasso.with() multiple times with same url, however each time with an image view having different dimensions, the image gets downloaded again.In Glide we have the methods .diskCacheStrategy() with DiskCacheStrategy.SOURCE for resolving the problem.is there any alternative way in Picasso ?

In this query we will get the solution for Glid but not for Picasso.how can i reuse the image without redownloading for different dimensions ImageView.

This is the code I'm using

Picasso.with(context)
                .load(URI)
                .placeholder(R.drawable.ic_profile_thumb)
                .resize(180, 180).centerInside()
                .into(viewHolder.imgThumbnail);

Solution

  • Picasso does not cache the image to disk, Picasso only has a memory cache. the Disk cache is done by the networking library(OKhttp). so the image written to the disk cache is never re-sized.

    if the same url image is downloaded multiple time you might have to check your networking library.

    If your project is using the okhttp library then picasso will automatically use it as the default downloader. If you are are using any other network library then you will have to write your own downloader and set it using

    Picasso.Builder(context).downloader(customDownloader)
    

    this link might make things clear