Baseflow / flutter_cache_manager

Generic cache manager for flutter
https://baseflow.com
MIT License
740 stars 429 forks source link

Question about calling download multiple times #274

Closed febg11 closed 3 years ago

febg11 commented 3 years ago

Hi

I was wondering what the behaviour is with calling .getSingleFile(webURL); multiple times with the same url?

For example i have a widget in a list view that will call the .getSingleFile(webURL); in the init. This same file could appear multiple times in the list, sometimes often. If the user ends up loading the same url twice in two widgets is the file actually downloaded twice? or does your code block and wait for the first download to complete and then return the cached file.

i''m worried the user could end up downloading the file 10-20 times if they scroll through the list really quickly and initialise lots of widgets with the duplicate urls, completely burning through mobile data and server bandwidth.

Thanks

renefloor commented 3 years ago

Nope, the cachemanager should only download once. If the download is finished the file should be returned from the cache. If the download is not yet finished the second call should return the file from the first download request. So calling getSingleFile multiple times is fine.