Update image to cache
First of all thanks for giving this beautiful library !!!!!!
I am load image from internal memory, i am using the same path for image i will update the image in particular path. If i am fetch the image through glide it return only old image, how can i solve this, my code is
Glide.with(mContext)
.load(path)
.asBitmap()
.animate(R.anim.activity_fade_in)
.placeholder(new AsyncColorDrawable(mResources))
.skipMemoryCache(false)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.override(width, height)
.into(new BitmapImageViewTarget(imageView) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
super.onResourceReady(resource, glideAnimation);
imageView.setVisibility(View.VISIBLE);
imageView.setScaleX(1);
imageView.setScaleY(1);
}
});
Read this wiki first: https://github.com/bumptech/glide/wiki/Caching-and-Cache-Invalidation#custom-cache-invalidation
I suggest you use .signature() and change the signature key itself when updating the file. You'll need to store that key for each file in a DB maybe. If you give more context about your app's wanted behavior/use case we may be able to suggest more specificly.
I also advise against skipMemoryCache(false) in general because it forces disk I/O unnecessarily; and .diskCacheStrategy(ALL) for local files, because it duplicates the image file in the cache directory.
Thanks for your suggestion. I have one more doubt if the image will store automatically bot disk and memory cache ?
Memory cache is temporary, it helps making back and forth scrolling faster. Disk cache stores the resized actual loaded image (RESULT) to load thumbnails or images from large sources faster; and it stores the original image (SOURCE) to prevent network I/O.
All caches, regardless of backing storage, use the same keying mechanism. So signature takes care of invalidating all of them.
How can i get cached image from Glide ?
Just load it, if it hits the cache it'll be faster than when it doesn't. There's no way to get which file is which model (URL, file on SD). You can look into downloadOnly if you want something like that, but that's only useful for remote URLs.
Ok thanks,
I have one more doubt, If i am load from AsyncTask it will through exception...How can i achieve it?
Image view is flickering when load image from cache, can you help me how to resolve this problem?
For the AsyncTask: always read the exception message, it should help figure out the problem. Most likely you're not starting the load on the UI thread (you need to put it into onPreExecute or onPostExecute, not doInBackground).
For the flicker you should open a new issue with complete description (see CONTRIBUTING.md) and screenshots or even video (adb screencapture + ezgif) if possible.