Caching with Glide - android

I'm using Glide and want to cache loaded images to local memory.
I searched for the same, and found out that images are cached automatically. You just need to provide the same loadURL , and Glide will search for image (along with other provided attrs : Resolution, Key, etc). The problem that I'm facing is that, I know what the loadURL will be at the time of initial resource load. But when the app wants to load the cached copy of, it doesn't have any loadURL info. How can I load cached images without providing loadURL (which was same at the time of initial load). Can I use any key (say StringKey), which can be associated with the image at initial load, and use the same key (without loadURL) at the time of loading cached copy? Thank you.

Glide doesn't support directly accessing the cache.
So, just persist the url the first time and use it later to load the cached image.
First time:
Glide.with(this).load(url).into(image);
save(url);
Later:
String url = getUrl();
Glide.with(this).load(url).into(image);

Related

Fetch Image from server by using url with Universal Image Loader

I am successfully fetching and caching image from server url by using Universal Image Loader. My DisplayImageOptions are given below.
new DisplayImageOptions.Builder().cacheInMemory(true)
.showImageOnLoading(R.drawable.home_back_img)
.showImageOnFail(R.drawable.home_back_img)
.bitmapConfig(Bitmap.Config.ALPHA_8)
.showImageForEmptyUri(R.drawable.home_back_img)
.build();
My problem is, when I updates image in server(with same file name), the image is not updated in application, its just using the cached file itself. Is there is any solution for this? Yes we can avoid caching, but then it might take some time to load the image every time, rather than avoid caching it would be nice if any solution exists. Help will be appreciated!
You must use different name to get the updated photo. Because , the image already stored in your local cache by the same name. So, It will never call to network to download the image .
Or , Clear your application cache , then you will get the updated image.

Android + Picasso: How to show images from URL properly form cache

I am developing Android app now where I need to store image Url in DB for each object and then load this image from the web (if connection is on) OR get it form cache (if not).
Picasso seems to be best lib for handling images in Android, so I starter using it. But I can not get how do I use it properly for my case. Even more - Images strangely are loaded into views right after they are first time get from API but if user starts app again, we can see placeholder only (even with internet connection on). Can someone suggest a solution or at least any kind of idea of best way to do this?
My code in Adapter (is is also same in ShowActivity):
String img_url = item.getImage(); // img_url is valid image url
Picasso.with(mContext).load(img_url).placeholder(R.drawable.plchldr).fit().centerCrop().into(holder.image);
I tried to use Picasso at the start as well, and found out that their caching system is horrible.
It would cache some images i downloaded, but not others, and would therefore leave alot of images with placeholders.
I suggest you try Universal-Image-Loader (https://github.com/nostra13/Android-Universal-Image-Loader). I'm currently using this to cache all images in my app, and it works flawlessly (Around 200 images atm).
Finally got the problem - API is returning valid image url BUT actually it (image) is hosted on S3 cloud and it is expiring till the user loads application again. So, actually saving expiring image URL is useless in this situation. I am not sure what will I do here (it seems that the only way here is hard one - storing images on SD as Bitmap). But I just wanted to tell this for those who will get similar issue.

Android Image fetching library

Hi i wanted to know is their any library in which we pass the URL and the image-view and it checks whether the images is present on device if not, then fetch image from URL and store to device and bind with the view passed. I tried writing the code but once the view is loaded and image is not fetched the images is never fetched in future unless i uninstall the app , i also tried universal image loader library and asynchronous image loader
Picasso is doing all things what you want.
It loads from internet and cache
It loads from cache
It loads from Local File
Read More Here And Here
Try volley library. you have a NetworkImageView I guess. Which fits your need.

With felipecsl Android-ImageManager library how can I replace a cached image

I am using felipecsl Android-ImageManager library to download some images from one of our servers and load it in a list view. In my Android application I have a feature to change that downloaded image from app side and upload it to server.
I do know how to load the image from URL because it is well documented with the above mentioned link. What I need is to change/delete a particular cached item and replace it with my new image from Android application side.
Let me explain it further. Normally what happens is, it loads an image from the provided URL and caches it in the manager's LRU and Disk cache. Then the second time call to that same URL, if the image is already cached, fetches it from the cache even I have set a different image from my application side.
Therefore how can I either delete that URL from cache OR set the new image for the cache of that same URL.
I have tried something like below, but seems it is not working.
imageManager.getCacheManager().getMemoryCache().put(ImageManager.getCacheKeyForJob(myUrl, jobOptions), bitmap);
That is not really supported by the library. If you need to do this kind of more advanced cache management, you can use Picasso (https://github.com/square/picasso), where you can set your own cache manager and have more control over your cached images.

Universal image loader recache from Internet

I use the Android Universal image loader,
and I set cacheInMemory and cacheOnDisc values to true.
Therefore, the imageloader downloads the images from the Internet,
and there images will be cached in order to load much more fast at the next time.
My question is that if these URLs of images are same but its contents are changed,
how the imageloader determine and resolve that situation and refresh these images of caches?
By default UIL doesn't check if image was changed on server. If image was cached on disk it will be used until it's deleted. So there are LimitedAgeMemoryCache and LimitedAgeDiscCache are exists for this case. They delete cached images after some time amount so updated images are loaded from server.

Categories

Resources