I use Picasso for picture viewer, which is able rotate images.
Problem is that when I rotate image and try to update it in viewer, it is not updating until I "destroy" application or use memory policy - .memoryPolicy(MemoryPolicy.NO_CACHE). I tried to use app without cache, but it is quite slower, so it is not solution.
Therefore I am looking for the way to clean up image from memory and update view. I can´t use parametr .rotate(90f), because Picasso handle correct rotation by itself, it is not working only temporary until memory is clean up.
This problem is not problem of file cache, it is problem of memory cache (based on my testing with memory cache settings). I also tried to invalidate file cache to be sure, but it didn´t helped as I expected.
Picasso.with(context).invalidate(filePath);
Picasso
.with(context)
.load(filePath)
.into(imageView);
Uff, I finally found it. Before I used Glide, which has parametr signature. Picasso has something similar called stableKey. When I use this, I do not have to care about cache, I just enable it and Picasso handle rest.
Picasso
.with(context)
.load(filePath)
.stableKey(uniqueFileAttribute)
.into(imageView);
Related
I have a scenario where i have to keep few images in offline mode. Now i am confused here that should i rely on Glide's cache or I have to put those images in Internal Storage?
Hopefully Glide will work, but need to know if there exists any limitation if i go with Glide. Here word cache is causing confusion.
Here is the information about underlying memory usage by Glide.
Glide uses DiskLruCacheWrapper as the default DiskCache. DiskLruCacheWrapper is a fixed size disk cache with LRU eviction. The default disk cache size is 250 MB and is placed in a specific directory in the Application’s cache folder.
Further underlying complexities of Glide are here. Hope confusion about the max memory Glide uses is cleared here and if customization is needed, that can also be achieved by following the link mentioned.
I implemented a routine which saves data from a json into database and after that if user gets offline, he can see all data. but picasso doesn't load the images after the first run. but when i run the application twice in online mode, after that picasso can load the images from cache in offline mode.
(it should cache images on the first run but it's not working)
appreciate any suggestion
https://stackoverflow.com/a/23281195/3664628
Picasso doesn't have a disk cache. It delegates to whatever HTTP client you are using for that functionality (relying on HTTP cache semantics for cache control). Because of this, the behavior you seek comes for free...
The main reason may be other images are evicting the older ones from the cache due to their size. You can load smaller versions or increase the size of the memory cache like this
Picasso p = new Picasso.Builder(context)
.memoryCache(new LruCache(Size))
.build();
If you don't want to save in cache, You can Additionally exclude that too using Memory Policy.
Picasso attempts to get the requested image from the memory first. If you would like Picasso to skip this step, you can call memoryPolicy(MemoryPolicy policy, MemoryPolicy... additional) on your Picasso request creator. MemoryPolicy is a simple enum with two values: NO_CACHE and NO_STORE. like this
Picasso
.with(context)
.load(UsageExampleListViewAdapter.eatFoodyImages[1])
.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
.into(imageViewFromDisk);
Additional Source : futurestud.io
I need to access an image that has been cached after it has been transformed (or cropped) using Picasso.
What I am doing is taking a large image resource, cropping a screen-size piece of it out of it at run-time, and setting it to the background of a RelativeLayout. So far I have used Picasso to accomplish this successfully.
Later in the app, I change the app layout by calling:
setContentView(R.layout.OTHER_LAYOUT);
I would like to then access the cache where Picasso stored the cropped version of the image, and dynamically set the background of OTHER_LAYOUT to the stored version of the cropped image.
This S.O. post seems relevant to accessing a bitmap cached by Picasso on device.
I am considering giving this solution a try. But one user's comment (a comment on the accepted answer) makes me wonder if there is a better way. Complicated solutions often seem more bug-prone.
"it seems can work. but in my opinion, it is not well offer. files are being saved somewhere. lib should give them to developers. it would be good instead of adding millions feature to picasso lib, adding very simple and essential features. I gave up to use picasso because of this. It has millions garbage features and very limited nice features."
Is there some way that Picasso allows me to access the image that was transformed and cached, and use it somewhere else (in a way that is simple & easy to use)?
If not, would another library give me greater convenience?
Don't think too much about reusing cached images, Picasso is very good at that and is well optimized for it. Just load the same URL / drawable and apply the transformation. If Picasso already cached it, it will be very fast, you can check if it is cached by setIndicatorsEnabled(true) on Picasso instance.
Here's what I currently understand:
I load http://www.example.com/imageA.png into my imageView using Picasso.
Picasso downloads imageA.png and in simple terms, caches it internally as "http://www.example.com/imageA.png".
I go offline, open my app, and Picasso tries to load http://www.example.com/imageA.png into my imageView again. It loads the image from the cache. I can see imageA even when my network isn't working.
This is all fine and dandy.
Say for example http://www.example.com/imageA.png now redirects to http://www.example.com/imageB.png and I repeat steps 1 and 2.
This time, I believe, Picasso caches it as http://www.example.com/imageB.png and therefore when I open my app in offline mode, I don't see imageA because it's cached as imageB.
Am I right?
Is there a way to force Picasso to cache it as its original URL?
Apparently you can add a stableKey to the request with the Request.Builder()
https://square.github.io/picasso/javadoc/com/squareup/picasso/Request.Builder.html#stableKey-java.lang.String-
Picasso manages memory cache only, so stableKey is only about that. Disk cache is managed by OkHttp. It's behaviour cannot be changed because com.squareup.okhttp.Cache is a final class.
I am using the Picasso library on my Android app to load images. I would like to add an option called "Clear images cache" on my app that would remove all the downloaded images from the cache, but obviously that would remove the downloaded images from my app only (I mean not from the other apps).
Is there a simple way to do that using Picasso? Using a native component?
Thanks!
You can clear in-memory cache in Picasso only per image:
Picasso.with(context).invalidate(imagePath);
Removing all cache is somewhat tricky and described here.
File cache is delegated to HTTP Client, so it's not possible to clear it from Picasso. For more information refer this answer.
Try this line of code given below, this removes the resource inside ImageView.
Picasso.with(context).setImageResource(0);