Picasso: URL cache expiration - android

I am developing android app that shows an image from URL. For this, I'm using Picasso library and it is working nicely. However, I think its caching time period depends on the headers of the image URL.
I have set Cache-Control:max-age=0 for image URL header and Picasso is only caching for few days and I want to store these images more than few days. Please help me find out the solution.

According to this answer there is no way to tell picasso to use some custom cache period.

Related

How to load images from internet in android app quickly?

I'm a beginner in android and i want to load some images from internet in my app. I heard about libraries such as Glide and Picasso. Can anyone please tell me which library is the best.
In your title you use the word "quickly". Theres no such thing, unless you have a cache implementation. As you pointed out those two libraries help in retrieving images from the web and displaying them into imageView, also support cache features so that images previously displayed can load faster in the near future.
Simple example of Picasso:
Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(imageView);
Want to know more about cache in Picasso? Check out this answer
According to this article here both are really nice to be used , but I would suggest Picasso because it just updated to 3.0 + it is lighter than Glide when it comes to :
library size and method count .

Glide caching behaviour

I have simple caching problem:
I have old "name.jpg", then customer uploads new "name.jpg" and clients dont see any changes, for them its still cached old "name.jpg".
I know how to turn off caching, but its not good decision, so I try to find better.
So question is:
How does caching work if I add get parameter after question mark?
For example I have url
http://example.com/name.jpg?cache_time=111
And then I replace it to
http://example.com/name.jpg?cache_time=222
Will it download second name.jpg and replace existing or not? I know its work with css or js files in browser, but know nothing about glide behaviour.
Whatever parameters you pass in the url query will be sent to the server serving the image and only if that server handles that exact parameter (cache_time) can there be any difference in behavior.
The caching glide does however is not based on what you send to the server, but rather on the configuration you give to glide.
I suggest you look up how glide handles caching, and perhaps manually invalidate the cache for a specific image when you know it has changed.
This is a good place to start: Remove image from cache in Glide library. It also has examples how to use signature()that is mentioned in the comment above.

How to load image from same url using glide or picasso in android?

Hi I have an wired issues stopping my development. I am working on the application similar to facebook having posts, comments likes and chat functionalities. In each functionality I need to load the user's profile picture. I can able to load the profile pictures when I was trying to login for the first time using glide libary. But when users changes the profile picture server is returning the same url but different image. How to invalidate or load image when it was updated and what are the best ways to handle this scenario?
Your answers are valuable to me. Thanks in advance.
like this:
Glide.with(MainActivity.this)
.load("URL")
.asBitmap().diskCacheStrategy(DiskCacheStrategy.SOURCE)
.placeholder(R.drawable.man_default)
.into(imgUserImage);
For Picasso you can use both MemoryPolicy and NetworkPolicy
Picasso
.with(context)
.load(url)
.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
.networkPolicy(NetworkPolicy.NO_CACHE)
.into(imageViewFromNetwork);
refer this its well explained here!
I think disabling cache strategy will be helpful for you as your url is same so
DiskCacheStrategy.NONE
From Here
difference between the enum parameters for the .diskCacheStrategy() method:
DiskCacheStrategy.NONE caches nothing, as discussed
DiskCacheStrategy.SOURCE caches only the original full-resolution image. In our example above that would be the 1000x1000 pixel one
DiskCacheStrategy.RESULT caches only the final image, after reducing the resolution (and possibly transformations) (default behavior)
DiskCacheStrategy.ALL caches all versions of the image
try using:
Glide.with(context)
.load(url)
.placeholder(R.drawable.ic_profile)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(ivUserProfilePhoto);
here is a relevant Question
I am glad to give you suggestion over it.
First, you should remember every profile has unique URL and it should be immutable on the server.
These issue is more sort of on server side because you never know on client side when other users changed their profile pictures but server knows.
Probable solution we have done for it
Whenever any user changes in profile picture we saving these picture on server with his timestamp and it attached to it's URL.
eg : http://image.pngtimestamp=1336t78387
So, now you have different URL for the user profile you don't have to change it on client side.
Only thing you have to take care for it is how you will get these updated URL for the specific user.We are requesting for URL to server whenever we chat with other user or see his profile. so every time we get the latest pic.
Even you want to improve performance for it you can request for updated images URL at the start of your application when user launch app so server can return you all the images after given timestamp.
Hope these helps you.

Image URL to create Bitmap android

I have a small problem, as I could convert a url from an image to a bitmap. The url string is obtained through a json that I download with Volley, and I need that bitmap to be able to give a personalized icon to a marker.
I think you can use Picasso Library here, and it will show the image with the given URL dynamically. There is much more benefits of using Picasso. Try that if it helps you.
And also there is no need to download the image to the user. It saves images cache to show the image if user returns in particular time-gap.
Volley supports loading images asynchronously to a bitmap.
Picasso supports loading images asynchronously to a bitmap.
Other image loading libraries may offer similar options, though since you already use Volley and Picasso, you may wish to stick with one of those.

Android wallpaper apps that update images every week

I see some wallpaper apps on the market and they update the images daily or weekly. I wonder how they do that. I use picasso library but I cannot do that with picasso. Is there anyone can help?
One way to achieve what you want is you can make webservice/api to pass image url from the server and now anytime whatever image url that api will respond/contains that you can load in your ImageView. And that't it.
Note - You must have a knowledge of making webservice and calling them and handling the http request response in advance for this before applying this approach.
Thanks.

Categories

Resources