-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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 cache is enabled, FileLoader should not make duplicate requests. #10644
Comments
Maybe related PR #10149 |
@mrdoob Currently we have two ideas to prevent duplicate requests.
Which do you prefer? BTW Three.js doesn't use Promise now. |
@takahirox |
Would you share your concerns about those approaches with us (again)? |
I know it's a bit late but i vote for a |
have FileLoader merge multiple concurrent requests for the same url (fixes #10644)
Description of the problem
Given the code below, only one request should be fired.
A
checks the cache and sees no pending requests.A
makes the request and stores the pending request in the cache as a Promise. The Promise will resolve the file.B
checks the cache and sees a pending request.B
waits for the Promise to resolve the file.A
andB
, both waiting on the Promise, triggers their callbacks at the same time with the same file response.I'd like to volunteer to work on this. In A-Frame, we often have been having to maintain a cache of promises to prevent duplicate requests. If it sounds reasonable, below are several possible implementations:
Change THREE.Cache to store promises that resolve files, rather than directly storing files. I think this is the optimal solution because requests will always be asynchronous. This is sort of a breaking change, but three.js applications don't often enable the cache, or don't care about the internals of the cache.
Create a separate cache object (
RequestCache
) for pending requests. The current Cache stays intact, but there is more logic to maintain both the pending and complete caches.Keep the pending request cache internal to the FileLoader. It'll just be a variable
var requestCache = {}
.We'd also need a Promise polyfill. They're less than 1KB gzipped if that sounds fine.
Three.js version
Browser
OS
Hardware Requirements (graphics card, VR Device, ...)
N/A
The text was updated successfully, but these errors were encountered: