-
Notifications
You must be signed in to change notification settings - Fork 144
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
Non-duplication of concurrent requests #51
Comments
Requests should not block. What you probably want is throttling that will put concurrent requests on hold and then respond with the cached response when the first request completes. |
Sorry; "block" was a misleading word. The idea is that the request is not being 'blocked' in the async sense, but rather the request is added to a queue rather than submitting multiple duplicate AJAX requests. Here's some rough code: function request(resource_name, callback) {
this_request = some_lookup_of_requests.get(resource_name);
if this_request.is_outstanding(resource_name) {
// by outstanding - the request has been made, and a response not
// yet received
subscribe(this_request, callback);
// when the ajax returns, the results are published
} else {
amplify.request(resource_name, function (...) {
this_request.no_longer_outstanding();
// make sure that subsequent requests do not subscribe when
// no ajax request is outstanding
callback(...); // tell the caller
publish(this_request, ...); // notify any subscribers
});
}
} This is not really caching in the traditional sense; it may be better to describe it as a subscriber/publisher alternative to multiple concurrent requests. I am not sure if this is something Plus it's fun. :) Cheers. |
I am facing the same problem. It would be very cool to have such a mechanisms. Or how it be implemented on our own? Any hints? |
When multiple concurrent requests occur, it would be valuable for amplify.js to reduce these requests to one ajax call.
For example, given:
Right now when I run this code (e.g. http://jsfiddle.net/Xg9gn/) two AJAX requests occur.
Obviously caching cannot occur until a request completes.
However, I believe a preferable model would be for the first request to block all future identical requests; those future requests would however subscribe to the results of the first request.
An option to force an AJAX request may be prudent (though I cannot think of a use case offhand).
Just a thought! :)
The text was updated successfully, but these errors were encountered: