glide icon indicating copy to clipboard operation
glide copied to clipboard

Update image to cache

Open thizisarun opened this issue 11 years ago • 9 comments

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);
                    }
                });

thizisarun avatar Sep 22 '15 11:09 thizisarun

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.

TWiStErRob avatar Sep 22 '15 22:09 TWiStErRob

Thanks for your suggestion. I have one more doubt if the image will store automatically bot disk and memory cache ?

thizisarun avatar Sep 23 '15 04:09 thizisarun

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.

TWiStErRob avatar Sep 23 '15 08:09 TWiStErRob

How can i get cached image from Glide ?

thizisarun avatar Sep 23 '15 10:09 thizisarun

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.

TWiStErRob avatar Sep 23 '15 10:09 TWiStErRob

Ok thanks,

thizisarun avatar Sep 23 '15 10:09 thizisarun

I have one more doubt, If i am load from AsyncTask it will through exception...How can i achieve it?

thizisarun avatar Sep 23 '15 12:09 thizisarun

Image view is flickering when load image from cache, can you help me how to resolve this problem?

thizisarun avatar Sep 23 '15 14:09 thizisarun

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.

TWiStErRob avatar Sep 25 '15 18:09 TWiStErRob