Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

$http service is also caching the config object #9004

Closed
dragosrususv opened this issue Sep 9, 2014 · 8 comments
Closed

$http service is also caching the config object #9004

dragosrususv opened this issue Sep 9, 2014 · 8 comments

Comments

@dragosrususv
Copy link

As per AngularJS documentation, each request (cached or not) should return the response with the "config – {Object} – The configuration object that was used to generate the request.". ( https://docs.angularjs.org/api/ng/service/$http ).

But that is not the case, as it's clearly visible on: https://github.com/angular/angular.js/blob/master/src/ng/http.js#L965

AngularJS is basically totally ignoring current request config and returns the cached one (cache miss one).

The fix for this is to replace the line above with:
cachedResp.then(function (response) {
response.config = config;
return response;
}, function (response) {
response.config = config;
return response;
}).then(removePendingReq, removePendingReq);

MORE INFO ON THE REAL USE CASE
Our app required an ajax service that would handle different cases:

  • when network timeout occurs, stack the requests and trigger them when network is on
  • when a session token expired, stack the requests, wait for the session token and trigger the requests again

In the above context, we were forced to add our own "currentRequests" array and we use a "requestId" number to identify the request when it comes back. The problem is that with this cache we are triggering requests 7 and 8 for instance and we get back 7 twice.

NOTE: I can create a branch and make a pull request with the above fix, if desired.

@dragosrususv
Copy link
Author

UPDATE: Found out a cleaner solution instead of the 1-line replace solution above. Can anyone please confirm that I could create a pull request for this? Does this seems reasonable?

@iorzetic
Copy link

We also have this problem in our project. Any idea if a fix could be included in one of the 1.3 release candidates?

@dragosrususv
Copy link
Author

@pkozlowski-opensource : do you think it would be reasonable to integrate @shahata's PR in one of the 1.3 release candidates? Shall we wait or just manually apply a patch for our product for the weeks to come?

@petebacondarwin
Copy link
Contributor

Assigning to @jeffbcross as he is dealing with @shahata's PR

@jeffbcross jeffbcross removed their assignment Sep 22, 2014
@jeffbcross jeffbcross modified the milestones: 1.3.0-rc.3, 1.3.0 Sep 22, 2014
@dragosrususv
Copy link
Author

rc3 is out but this is not merged - any news?

@dragosrususv
Copy link
Author

@petebacondarwin / @jeffbcross : the PR for this issue is still opened and 1.3.0 was released - we are forced to go in production with an updated version of AngularJS (manually patched it). Is there any way we could consider integrating this soon?

Very disappointed of the lack of interest on your side. As community we can only raise bugs and fixed them ourselves, but not having the pro-active attitude towards such an approach, that I cannot understand.

@lgalfaso
Copy link
Contributor

@dragosrususv please tone down your comments

@dragosrususv
Copy link
Author

@lgalfaso : please mind this issue was labeled with 1.3.0-rc3 and someone forgot to add it. allow me to say that professionally speaking, this is not ok - in business this may cause you lots of trouble (as employer or employee). do you agree?

@shahata shahata closed this as completed in facfec9 Dec 6, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants