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

feat(http): allow caching for JSONP requests #8356

Closed
wants to merge 1 commit into from
Closed

feat(http): allow caching for JSONP requests #8356

wants to merge 1 commit into from

Conversation

shahata
Copy link
Contributor

@shahata shahata commented Jul 26, 2014

Closes #1947

@mary-poppins
Copy link

Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.

  • Uses the issue template (#8356)

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

@shahata
Copy link
Contributor Author

shahata commented Jul 26, 2014

This was far more trivial than I initially expected 👀

@trirach1
Copy link

Hi
Le 26 juil. 2014 20:32, "Shahar Talmi" notifications@github.com a écrit :

Closes #1947 #1947

You can merge this Pull Request by running

git pull https://github.com/shahata/angular.js jsonp-cache

Or view, comment on, or merge it at:

#8356
Commit Summary

  • feat(http): allow caching for JSONP requests

File Changes

Patch Links:


Reply to this email directly or view it on GitHub
#8356.

@petebacondarwin
Copy link
Member

Hi @shahata - did you check that this actually works in practice, since the original issue discusses the fact that the JSON_CALLBACK label will be replaced with a new value every time so breaking the cache. I wonder if the ngMock $httpBackend is intercepting too early before this occurs?

@petebacondarwin
Copy link
Member

Actually looking deeper into the code it seems that the cache check is done in $http and the JSON_CALLBACK replacement is done in $httpBackend so I guess we are OK with hitting the cache.

@petebacondarwin petebacondarwin added this to the 1.3.0 milestone Jul 26, 2014
@petebacondarwin petebacondarwin self-assigned this Jul 26, 2014
@petebacondarwin petebacondarwin modified the milestones: 1.3.0-beta.18, 1.3.0 Jul 26, 2014
@shahata shahata added cla: yes and removed cla: no labels Jul 26, 2014
@shahata
Copy link
Contributor Author

shahata commented Jul 26, 2014

Yes, I also noticed that comment, but from what I see it is either wrong or maybe the code has changed since then, because now the url manipulation is decoupled nicely from the cache.

@shahata
Copy link
Contributor Author

shahata commented Jul 26, 2014

Here's the plunker I played with to see that it works in practice - http://plnkr.co/edit/XRCFYD7KlgvLTLGPtTcn?p=preview

@petebacondarwin
Copy link
Member

Here is another version of the Plunker: http://plnkr.co/edit/bs7joENeXtEW6LzzvVBB?p=preview
Your one failed because I didn't have a valid twitter API key or something. On can see that the promise is requested and a promise is resolved repeatedly in the console but in the network tab you can see that only one real HTTP request is made.

@petebacondarwin
Copy link
Member

So LGTM - I'll merge

@@ -886,7 +886,8 @@ function $HttpProvider() {
promise.then(removePendingReq, removePendingReq);


if ((config.cache || defaults.cache) && config.cache !== false && config.method == 'GET') {
if ((config.cache || defaults.cache) && config.cache !== false &&
(config.method === 'GET' || config.method === 'JSONP')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSONP requests are always essentially GET requests, so it would be cool if we could just rename the method to GET --- but this would take a bit more refactoring, so this is fine for now.

I think this implementation is generally fine, so LGTM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

$http cache doesn't work for JSONP requests
6 participants