Reputation: 825
I have an android app which has profile image. The user can edit his/her profile image. I'm using Picasso to load images, but every time I load profile image, Picasso loads old image.
When I upload profile image I don't change it's url, so profile image url for every user is constant.
First question: should I change profile image url every time user change profile image?
Second question: When user change his/her profile image I invalidate Picasso to load new image using this code:
picassoInstance.load(url)
.networkPolicy(NetworkPolicy.NO_CACHE)
.transform(new CircleTransform())
.placeholder(dr)
.into(imageView);
But Picasso show me the old one. And one more thing: I load image url into imageView without calling networkPolicy method at first. How should I handle this problem?
Upvotes: 0
Views: 3324
Reputation: 9
You need to invalidate the file before loading use the code given below:
Picasso.with(getActivity()).invalidate(file);
To know more details kindly study the Picasso documentation from their website.
Upvotes: 0
Reputation: 825
I find where problem is: I turned down disk cache but not memory cache. I should use this code:
picassoInstance.load(url)
.networkPolicy(NetworkPolicy.NO_CACHE)
.memoryPolicy(MemoryPolicy.NO_CACHE)
.transform(new CircleTransform())
.placeholder(dr)
.into(imageView);
I use this link to: picasso-influencing-image-caching
Thanks everybody
Upvotes: 0
Reputation: 452
Add this class to the com.squareup.picasso package.
package com.squareup.picasso;
public class PicassoTools {
public static void clearCache (Picasso p) {
p.cache.clear();
}
}
Because cache has package visibility, this util class can clear the cache for you. You just have to call it:
PicassoTools.clearCache(Picasso.with(context));
Upvotes: 0
Reputation: 5865
Every Image has different name, whenever new image uploaded you have to update your image Url
Eg. current url : https://photographylife.com/nikon-d810-high-resolution-image-samples
where Image name is : nikon-d810-high-resolution-image-samples
and after uploaded new image, name will be different for example : image-sample
so you need to update that image Url : https://photographylife.com/image-sample
with new name
try this, i telling you cause im doing the same hope this will help you!
Upvotes: 1
Reputation: 683
Using Glide instead of Picasso because Glide recommended by google http://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en
Preventing for caching in Glide
Glide.with(DemoActivity.this)
.load(Uri.parse("file://" + imagePath))
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(mImage);
Upvotes: 0
Reputation: 24231
So lets just discuss one by one:
Should I change profile image url every time user change profile image?
No. You might think of other ways around. In my case, I download the picture each time the url changes with a specific name of the user (as we're considering profile picture). So when I loaded the image with Picasso I passed the file path instead of the URL so that, it won't fetch from the URL each time. Picasso doesn't do that either actually. It maintains a cache. If the file doesn't exist, just put a placeholder.
When user change his/her profile image I invalidate Picasso to load new image using this code:
I don't see any invalidate code here in your code. I would refer to this link to see how they've solved the cache problem.
I load image url into imageView without calling networkPolicy method at first.
So if you fetch the image from the external storage, I don't think there's a necessity to do so.
And another suggestion is to use Glide in these cases. This is almost the same thing as Picasso, but personally I like to use Glide instead of Picasso.
Hope that helps.
Upvotes: 0