Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If images are cached, why are some images still trying to load on airplane mode? #371

Closed
owlstack opened this issue Nov 10, 2016 · 17 comments

Comments

@owlstack
Copy link

owlstack commented Nov 10, 2016

I have my images cached and then I turn on airplane mode. Once, I'm in airplane mode, I navigate to the detail screen with that image. Why is the image trying to load when I'm on airplane mode? It should either show the cached image or just immediately show the placeholder if it can't get the image from the cache. Why is there a delay to fetch the image if it's stored locally or not found?

I think the images are still trying to fetch from the network/remote server and not locally.

Is this issue fixed?

EDIT: Tested on Xamarin.Forms Android app. This also might because of the retry count and retry delay but if I have no internet, should it retry or wait until I have intermittant or stable connection? If no internet, should it just display placeholder immediately instead of retrying?

@daniel-luberda
Copy link
Member

  • Do you experience it on a device or an emulator?
  • Do you use any custom path for disk cache?
  • FFImageLoading is using temp cache folders. Do you clear your app cache somewhere?

I tested sample app from repo on a disconnected device, not a single http request and images are loading fine from disk. Could give more details / make a reproduction?

If no internet, should it just display placeholder immediately instead of retrying?

It's not implemented yet, but you can implement it yourself by using custom DownloadCache, just extend it and override DownloadAsync method and throw exception when there's no internet connection.

@daniel-luberda
Copy link
Member

@owlstack Any news?

@owlstack
Copy link
Author

@daniel-luberda It seems to be working. Just need to test once more.

I have a question. One of my testers told me they expect the same image to be cached for X amount of time and when they change the image on the server, it changes to the new image and it's not cached for X amount of time. Is this correct behavior if the image name changes (creating a new url?)? If the image changes with a new image name, it will override the previous image before the time set of the cache duration?

@alanspires
Copy link
Contributor

Caching is done off the URL so if the image name changes And the url changes the image should re download and cache for the x amount of time

@owlstack
Copy link
Author

@alanspires so the best way for the testers to test the cache duration works is to upload a new image that has the same name as the old image right? Would that work? Thanks!

@alanspires
Copy link
Contributor

@owlstack if a user uploads a new image with the same name I don't believe the library will even re-download it as it will see that it is already in it's disk cache. But if you are testing just the cache expiration then once the original image expires locally it should re-download it and get the new image you used to replace the old one.

@owlstack
Copy link
Author

Thanks. That's what I thought. I told my QA team.

@owlstack
Copy link
Author

owlstack commented Dec 1, 2016

@daniel-luberda @alanspires

Can you elaborate or provide an example on how I can do this?:

If no internet, should it just display placeholder immediately instead of retrying?
It's not implemented yet, but you can implement it yourself by using custom DownloadCache, just extend it and override DownloadAsync method and throw exception when there's no internet connection.

Currently, I'm having these two issues:

Placeholder displayed for a second but while scrolling the page, image disappear.

Placeholder takes long time to display in offline mode. The placeholder should display immediately if image is not cached (I'm guessing what you mentioned above can fix this?)

Currently, since for listviews I have to set the binding for images. I thought maybe setting the CachedImage source directly to the errorplaceholder image would immediately show the placeholder, then when I gain connectivity, retry or show the correct image but I am still seeing the behavior of no images showing up until a placeholder is set after a few seconds. Should I add a loading placeholder as well?

E.g.

productImage = new CachedImage
{
	HeightRequest = 80,
	WidthRequest = 80,
	Aspect = Aspect.AspectFit,
	HorizontalOptions = LayoutOptions.Center,
	VerticalOptions = LayoutOptions.Center,
	CacheDuration = TimeSpan.FromDays(14),
	RetryCount = 3,
	RetryDelay = 250,
	ErrorPlaceholder = "thumb_placeholder.png",
	Source = "thumb_placeholder.png"

};
			
protected override void OnBindingContextChanged()
{
	base.OnBindingContextChanged();
	
	if (productImage != null)
	{
		productImage.SetBinding(CachedImage.SourceProperty, new Binding("ThumbnailImage", BindingMode.OneWay, converter: new UriConverter()));
	}
}

@daniel-luberda
Copy link
Member

daniel-luberda commented Dec 14, 2016

There was a bug with default cache duration: #396

Placeholder takes long time to display in offline mode. The placeholder should display immediately if image is not cached

Are you talking about loading or error placeholder? If it's error placeholder, you can control time after it's shown with custom configuration HttpHeadersTimeout / HttpReadTimeout properties.

@owlstack
Copy link
Author

I am talking about the error placeholder.

How should I use those properties to show it if I'm also trying to do a retry?

In the end, I solved the issue by using a loading placeholder.

The bug with the default cache duration... when was it fixed? Which version of the image library is the fix included in? Thanks!

@daniel-luberda
Copy link
Member

How should I use those properties to show it if I'm also trying to do a retry?

It's simple. TimeAfterErrorPlaceholderIsShown = numberOfRetries * Timeout

The bug with the default cache duration... when was it fixed? Which version of the image library is the fix included in?

Newest prerelease.

@daniel-luberda
Copy link
Member

Please reopen if you still experience this.

@rohitkadlag777
Copy link

rohitkadlag777 commented Jan 22, 2017

@daniel-luberda :
Facing the performance issue while loading the images from cache. I have cached the images before using the app in offline mode. And using my application in offline mode.Still images are loading as if they are downloading from internet.My internet is off while using application. I have cahche more than 10000 thousand images.Ideally images from cache should load instantly.Below is my code snippet for cached Image:-
cachedImage = new CachedImage()
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Start,
CacheDuration=TimeSpan.MaxValue,
Aspect = Aspect.Fill,
DownsampleToViewSize = true,
TransparencyEnabled = false,
ErrorPlaceholder = "error.png",
};

@daniel-luberda
Copy link
Member

daniel-luberda commented Jan 23, 2017

@rohitkadlag777

  • When a device is in offline mode, do images show correctly? If yes, they must be loaded from disk cache, which is a correct behaviour.
  • If yes, is it possible that you have so many images that not all of them can be put into memory cache, that's why they're loaded from disk (that's why it's slower). You can change memory cache size by using custom configuration (See wiki).

@Motaz-Al-Zoubi
Copy link

Let's say that I have two instances of CachedImage in different classes that are loading the same image from the Disk (same uri).
and let's say that the first instance loads the the image before creating the second instance,
so the first instance will load the image and cache it.
when creating the second instance does it take the image from cache or it loads the image from disk and cache it again.

in simple words, is the caching performed per CachedImage Instance or per some other service provided by FFImageLoading Library

@sirimanu
Copy link

sirimanu commented Sep 1, 2017

@Motaz-Al-Zoubi Even I want to know whether the image from the same uri is cached multiple times for multiple instances or only once.
@daniel-luberda Can you clarify?

@daniel-luberda
Copy link
Member

It's cached only once, globally. Every instance uses the same bitmap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants