问题描述
我知道这是一个非常基本的问题.我试图找到众多解决方案,但我无法理解它们.
I know it is a very basic question. I have tried to find the numerous solution but I am not able to understand them.
我想要的
将图像上传到服务器,作为回报,我得到URL,但是问题是在使用该URL设置图像时,设置了旧图像.发生这种情况是因为滑行占用了旧的缓存,而不更新缓存.
upload image to the server and in return I am getting URL but the problem is while setting the image using this URL, the old image is set. This is happening because the glide is taking old cache and not updating the cache.
如何解决此问题.
Glide.clear(profilePic);
Glide.with(getApplicationContext())
.load(url)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.skipMemoryCache(true)
.transform(new CircleTransform(MainProfile.this))
.into(profilePic);
当前,图片已更改,但是当我单击后退"按钮并返回到此活动时,它将加载旧图像.像这样从缓存加载图像.
currently, the pic is changed but when I click the back button and come back to this activity then it loads an old image. Loading the image from cache like that.
//setting up the profile pic
Glide.with(getApplicationContext())
.load(userProfilePicUrl)
.asBitmap()
.centerCrop()
.into(new BitmapImageViewTarget(profilePic) {
@Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(MainProfile.this.getResources(), resource);
circularBitmapDrawable.setCircular(true);
profilePic.setImageDrawable(circularBitmapDrawable);
}
});
问题是,当我回到此活动时,它显示的是旧照片而不是新照片.
The problem is when I come back to this activity it shows old pic instead of new one.
推荐答案
RequestOptions 提供类型独立的选项,以自定义最新版本的Glide中的Glide负载.
RequestOptions provides type independent options to customize loads with Glide in the latest versions of Glide.
制作一个 RequestOptions 对象,并在加载图像时使用它.
Make a RequestOptions Object and use it when we are loading the image.
RequestOptions requestOptions = new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.NONE) // because file name is always same
.skipMemoryCache(true);
Glide.with(this)
.load(photoUrl)
.apply(requestOptions)
.into(profile_image);
这篇关于使用滑行时删除缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!