Async file download (fetch) and cache
- m4recek
- Member | 5
Hi, I came across a problem with file downloads. I want to download a file from internet (fetch) and then run code on top of it. Problem is that file is fairly big, and service which is providing this file is fairly unreliable.
So I am looking for a solution which will work as:
- code tries to load a file
- if file is not on a local machine (cached):
2.1 create async request to fetch a file
2.2 return false to code above.
- if a file is on a local machine (cached)
3.1 check TTL of a file (invalidate cache if necessary)
3.2 return file content or go to step 2
- ensure that fetch will happen only in one thread. We dont want to download same file twice for 2 concurent requests
Is something like that possible in NETTE? Or I need to create underlying daemon for dealing with caching and concurrency.
Last edited by m4recek (2014-06-10 23:56)
- Filip Procházka
- Moderator | 4668
Nette doesn't have a library for async downloads, but there is nothing stopping you from using any other library that does, with nette. Just search “async curl” on packagist or github and try using one of the results.
I would personally give a shot to kaja47/async-curl, but I can't tell if you will be able to use it without documentation.