Store images in picasso with a cache key

Is there a way to load images into the Picasso image cache by specifying the cache key used?

On the side of the note, if this is not possible, I made the necessary changes, but I'm not sure how to rebuild the bank. Any Picasso remodeling instructions are greatly appreciated.

+5
source share
3 answers

You can call stableKey on your requestCreator object.

https://square.imtqy.com/picasso/2.x/picasso/com/squareup/picasso/RequestCreator.html#stableKey-java.lang.String-

It will look like this: Picasso.with(context).load(yourURL).stableKey(yourKey).into(textView);

+2
source

I did not find open access to this function, but for me this is a workaround:

 //1. Init picasso, create cache mCache = new LruCache(mContext); mPicasso = new Picasso.Builder(mContext).memoryCache(mCache).build(); //2. Load bitmap mPicasso.load(uri).resize(mThumbWidth, mThumbHeight).centerCrop().into(v, callback); //3. In case of error (for example, in callback), you can manually download the picture and store to cache Bitmap bmp = <custom load> //make key StringBuilder sb = new StringBuilder(uri); sb.append("\nresize:").append(mThumbWidth).append("x").append(mThumbHeight).append("\ncenterCrop\n"); mCache.set(sb.toString(), bmp); 

Please note that the key is using uri and your custom transformation (resizing, centerCrop ant like this, see more at com.squareup.picasso.Utils # createKey)

0
source

it worked for me

 String strUrl = WWW.sultan.com....; Bitmap = bitmap; Picasso.with(Profile.this).load(strUrl).into(new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { userImage.setImageBitmap(bitmap); this.bitmap = bitmap; //this can be used any where in the code } @Override public void onBitmapFailed(Drawable errorDrawable) { } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { } }); 
0
source

Source: https://habr.com/ru/post/1202566/


All Articles