FFImageLoading icon indicating copy to clipboard operation
FFImageLoading copied to clipboard

Request: Provide way to download & cache images without assigning to views

Open ahohns opened this issue 10 years ago • 42 comments

Is it possible to provide a way to download & cache an image (either disk, memory, or both) without assigning the image to a view?

Use case example: We'd like to iterate through a list and call a method that downloads & caches an image from each item in the list. This is so the images are pre-cached and display quicker when scrolling for certain listviews within an app.

Currently images are only loaded when the cell becomes visible which at times can provide a slower than ideal experience especially when the network link is slow.

ahohns avatar Feb 11 '16 00:02 ahohns

This would be handy

Sent from my iPhone

On Feb 10, 2016, at 5:14 PM, Aaron Hohns [email protected] wrote:

Is it possible to provide a way to download & cache an image (either disk, memory, or both) without assigning the image to a view?

Use case example: We'd like to iterate through a list and call a method that downloads & caches an image from each item in the list. This is so the images are pre-cached and display quicker when scrolling for certain listviews within an app.

Currently images are only loaded when the cell becomes visible which at times can provide a slower than ideal experience especially when the network link is slow.

— Reply to this email directly or view it on GitHub.

ghost avatar Feb 11 '16 14:02 ghost

+1

dspacey89 avatar Feb 11 '16 15:02 dspacey89

+1

andrewSvsg avatar Feb 12 '16 07:02 andrewSvsg

+1

c1rus avatar Feb 12 '16 07:02 c1rus

I'd like to see this done too.

adrianknight89 avatar Feb 14 '16 16:02 adrianknight89

We could have some helper method to do that, but in my opinion, we also need to modify scheduler to support task priorities to avoid normal image loading tasks starvation.

daniel-luberda avatar Feb 18 '16 13:02 daniel-luberda

@ahohns @highplains @dspacey89 @andrewSvsg @c1rus https://github.com/molinch/FFImageLoading/commit/74d161a5683bd9008aef8aa764eb9e8f7429f9a0 I added DownloadImageAndAddToDiskCache helper method for a start. What do you think? As always, some testing needed.

daniel-luberda avatar Feb 23 '16 20:02 daniel-luberda

Is there a way to check if the image has already previously been downloaded first?

On Tue, Feb 23, 2016 at 1:19 PM, Daniel Luberda [email protected] wrote:

@ahohns https://github.com/ahohns @highplains https://github.com/highplains @dspacey89 https://github.com/dspacey89 @andrewSvsg https://github.com/andrewSvsg @c1rus https://github.com/c1rus 74d161a https://github.com/molinch/FFImageLoading/commit/74d161a5683bd9008aef8aa764eb9e8f7429f9a0 I added DownloadImageAndAddToDiskCache helper method for a start. What do you think?

— Reply to this email directly or view it on GitHub https://github.com/molinch/FFImageLoading/issues/143#issuecomment-187885857 .

ghost avatar Feb 23 '16 20:02 ghost

Not currently, I could modify method to just download image if it's not in cache. What do you think?

daniel-luberda avatar Feb 23 '16 20:02 daniel-luberda

Ya that could work, can you return a value from the function that indicates whether the image exists in the cache when the function exits?

ghost avatar Feb 23 '16 22:02 ghost

@highplains Yes, I just commited that.

daniel-luberda avatar Feb 23 '16 22:02 daniel-luberda

nice any way to get that into a RC on nuget?

On Tue, Feb 23, 2016 at 3:35 PM, Daniel Luberda [email protected] wrote:

@highplains https://github.com/highplains Yes, I just commited that changes.

— Reply to this email directly or view it on GitHub https://github.com/molinch/FFImageLoading/issues/143#issuecomment-187945428 .

ghost avatar Feb 23 '16 22:02 ghost

RC2 nuget already released. Could you test it?

daniel-luberda avatar Feb 23 '16 23:02 daniel-luberda

ya ill give it a go tomorrow for sure

On Tue, Feb 23, 2016 at 4:14 PM, Daniel Luberda [email protected] wrote:

RC2 nuget already released. Could you test it?

— Reply to this email directly or view it on GitHub https://github.com/molinch/FFImageLoading/issues/143#issuecomment-187958702 .

ghost avatar Feb 23 '16 23:02 ghost

What does the lib do if I'm downloading the same images in the background that the user is requesting while scrolling? Just out of curiosity.

ghost avatar Feb 23 '16 23:02 ghost

For now, prioritizing is not implemented (it's on a todo list), so basically it just runs those downloads simultaneously with "standard" image downloading tasks.

daniel-luberda avatar Feb 23 '16 23:02 daniel-luberda

Did anyone test it?

daniel-luberda avatar Feb 26 '16 14:02 daniel-luberda

Looking good so far!

ghost avatar Mar 03 '16 21:03 ghost

@highplains Thanks for testing!

I want to modify that method, so the downloading would only work when no other image loading tasks are running. My idea is to:

  • Modify ITaskScheduler so it would expose HasPendingTasks property
  • DownloadBytesAndCacheAsync (https://github.com/molinch/FFImageLoading/blob/master/source/FFImageLoading.Shared/ImageService.cs#L373) will not be called until HasPendingTasks = false, wait otherwise.

What do you think about this approach? @molinch

daniel-luberda avatar Mar 04 '16 16:03 daniel-luberda

In my app pictures are downloading frequently as the user scrolls, i would still like to be "pre-downloading" pictures later in the list while that is happening. Can you open it up as a options so we can choose?

On Fri, Mar 4, 2016 at 9:40 AM, Daniel Luberda [email protected] wrote:

@highplains https://github.com/highplains Thanks for testing!

I want to modify that method, so the downloading would only work when no other image loading tasks are running. My idea is to:

  • Modify ITaskScheduler so it would expose HasPendingTasks property
  • DownloadBytesAndCacheAsync ( https://github.com/molinch/FFImageLoading/blob/master/source/FFImageLoading.Shared/ImageService.cs#L373) will not be called until HasPendingTasks = false, wait otherwise.

What do you think about this approach? @molinch https://github.com/molinch

— Reply to this email directly or view it on GitHub https://github.com/molinch/FFImageLoading/issues/143#issuecomment-192348639 .

ghost avatar Mar 04 '16 16:03 ghost