(Glide) Getting image from cache if it exists - android

I have trouble when I'm using Glide in my app. As I've understood, if image was downloaded once and I request image from cache from other activity, Glide must show image quick. And I got this behavior, but not in my app. Image loads very slow (about 3 seconds), although in another app it was about 0.4 second.
My code with calling Glide:
Glide.with(this)
.load(url)
.signature(new StringSignature(url))
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(mHeader);
And in other activity code are same.
May you help me?
Thanks

You don't need the signature(url) part, the model (url String in your case) is already a part of the cache key.
The problem may be that your header changes size. The view size (= resulting Bitmap size) needs to be constant for a cache hit. However since you're doing ALL caching the load should still be fast. Is there anything changing in the url maybe, like a sessionid or similar? That would make the cache miss.
If the url you're loading is an animated GIF RESULT caching can be the culprit, here's a reference.

Related

Glide Does not use Cached Image

Hi I am using Glide to load image and after following many posts I tried to implement Glide caching using
RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL).centerCrop()
Glide.with(mContext)
.load(imageUrl)
.transition(ImageUtil.crossFadeTransition())
.apply(ImageUtil.requestOptionsForSlider())
.listener(glideRequestListner)
.into(imageView)
My knowledge is that if I use diskCacheStrategy(DiskCacheStrategy.ALL) then the above Glide image loading code will automatically use cache if available, or download if not, right?
But I see everytime the code is called, (checking my internet speed meter) that it is always fetching/downloading from the given url (even though I can see the app memory size is increasing).
I even tried this code also-
val future: FutureTarget<File> = Glide.with(mContext)
.load(imageUrl)
.downloadOnly(500, 500)
Nothing seems to work
What should I do so that Glide uses cache if available?What is wrong with my conception about the caching implementation? Any help is very much appreciated!
Are you sure it is downloading again ? did you try disabling internet just before loading the images ?
Otherwise, is your image URL always the same for the same image ? (as Glide uses it as a cache key).
You can use this in the following calls to check if images are in cache:
Glide.with(fragment)
.load(url)
.onlyRetrieveFromCache(true)
.into(imageView);

glide take time to load image even if image load from cache?

I have RecyclerView where image load from server URL. so I use Glide library to load an image, glide store image into cache to reload as fast as possible.
I use a placeholder() as a loader for loading image first time, but if I off the internet and start app its still load placeholder first and then load an image into ImageView.
So, my question is, is there any way to load an image into ImageView so user experience like smoothness (offline) app while loading images
Glide.with(context)
.load(www.abc.com/abcd.jpg)
.placeholder(R.drawable.placeholder)
.into(viewHolder.ivSleepImage)
you can check this app Walking UP it loads image first time than there is no loader, and next time when image load means when you open app image already loaded in list.
Please somebody help me to achieve this task
There are 2 ways you can do that task but it can be very lengthy because storing and loading is not the way to approach in the android development
1.Store the data in the cache
2.store data in the database
the cache strategy is relatively easy. as you are requesting the data from the server if the connection is not available then you have to load data from the cache. Same can be said from the database but it is very lengthy and can be very slow.
A quick solution to your problem would be to add diskCacheStrategy to your Glide call. This would help you cache ALL versions of your image and thus reduce load-time. Here's an implementation:
Glide.with(context)
.load(www.abc.com/abcd.jpg)
.placeholder(R.drawable.placeholder)
.into(viewHolder.ivSleepImage)
.diskCacheStrategy(DiskCacheStrategy.ALL)
I hope this helps. Merry coding!

Android picasso cache images

In documentation in written that picasso caches images downloaded , but i havent seen an example how to call that image again from cache.
Here i first time load the image :
Picasso.with(getActivity())
.load(thirdArticle.getImageURL())
.resize(200, 150)
.centerCrop()
.into(mainThreeArticleImage);
Second time when i call same code above it shouldnt get from cache ???
If not, how to call cached images by that url ??
Picasso automatically caches the loaded images, So that next time they will be loaded from the cache. You can check whether the image is loaded from the web, cache or disk by enabling the indicator
Picasso.get().setIndicatorsEnabled(true);
Indicators will be shown for each image, specifying where the image is loaded from.
I got the reference from here

Picasso: Loading cached image from disk too much slow

So, I was starting my project and wants to use Picasso in my project because its popular and used by many projects out there.
I included picasso using gradle and tried loading facebook profile url with this. http://graph.facebook.com/rohitiskul/picture.
It worked very well. It loaded image from network without any issues. I restarted the app.(Without actually killing the process). It showed me the same image instantly cached in Memory.
But then, I killed the app (force stop) and restarted. It took almost 10+ seconds to load the image. And that image was loading from the disk when I checked in the debug logs.
My code looks like this -
In MainActivity-
Picasso.with(context)
.load("http://graph.facebook.com/rohitiskul/picture")
.into(imageView);
In application class-
Picasso picasso = new Picasso.Builder(this)
.indicatorsEnabled(true).loggingEnabled(true).build()
Picasso.setSingletonInstance(picasso);
Anyone with the similar problem? Any solution would be helpful.
I tried loading same Url with UniversalImageLoader and it was fast when fetching cached image from disk.
Edit
Earlier while playing with my app, I found out that Picasso wasn't loading the disk cached image when device was offline.
I encounter the same problem,
but find only slow for the first image, later images will be fast.
Probably it needs a warm-up (loading index cache) ?
Okay i got your problem. I have fixed it by doing this
Picasso.with(context)
.load("http://graph.facebook.com/rohitiskul/picture")
.networkPolicy(NetworkPolicy.OFFLINE)
.into(imageView, new Callback() {
#Override
public void onSuccess() { }
#Override
public void onError() {
// Try again online if cache failed
Picasso.with(context)
.load("http://graph.facebook.com/rohitiskul/picture")
.into(imageView);
}
});
Explanation:
Picasso will look for images in cache.
If it failed only then image will be downloaded over network. In your case from facebook.
This issue I had also faced earlier, with this what I understood that Picasso refer the cached image based on image name mentioned in the URL.
In your case you don't have image name in URL like 'image1.jpg'. Due to which Picasso is finding it difficult to read from cache and it downloads the image everytime
You can give a try to image containing the image name in URL and that will work
Picasso doesn't offer disk cache out of the box. Instead, it relies on an Http Cache.
Make sure you add OkHttp to your dependency list.
Add a string identifier with the stableKey method when making the request so Picasso can identify your requests and quickly load it from the cache.
Example:
Picasso.Builder(context).loggingEnabled(true).build()
.load(imageUrl)
.stableKey("myImage")
.into(imageView)

Android Picasso Reload Image from cache fail

Its been sometime I started using Picasso for Image Loading in Android. The usual scenario is , it downloads images and cache it and if later needed it retrieves from Cache.
just found this use case,
if the ImageURL ends with .(jpg,png, etc etc .....)
Ex:http://www.androidguys.com/wp-content/uploads/2014/07/android-for-wallpaper-8.png
Picasso work as expected ,
but if the imageURL's are of type
http://cloud.clubsalive.com.au/download/33/404e58cf-d890-4eaa-981e-c2f3442f9348
then its not reloading from cache , its downloading every time when the view is loaded.
Is it a normal behavior of Picasso ???
Your image is giant. Try to increase cache size. Or scale down your image

Categories

Resources