Skip to content
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

feat(common): add a common module with TransferHttpCacheModule #823

Merged
merged 1 commit into from
Oct 11, 2017

Conversation

vikerman
Copy link
Contributor

Add a TransferHttpCacheModule that when included in the App module will start caching Http requests on the server and transfer the cache to the client.

This will help avoid duplicate requests from the client for requests that the server application already made.

@@ -0,0 +1,105 @@
import 'rxjs/add/observable/of';
Copy link

@Toxicable Toxicable Oct 10, 2017

Choose a reason for hiding this comment

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

any reason to not replace this with of import rather than modifying the prototype?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. Will fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm - This seems to be the canonical way to include Observable.of. What did you have in mind?

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks - Done

@Inject(PLATFORM_ID) private platformId: Object) {
// Stop using the cache if the application has stabilized, indicating initial rendering is
// complete.
toPromise

Choose a reason for hiding this comment

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

Shouldn't this be wrapped in a if(isPlatformBrowser())?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. Both the server and client stop after initial render.

Copy link

@Toxicable Toxicable Oct 10, 2017

Choose a reason for hiding this comment

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

Then wouldn't it be better to use the BEFORE_APP_SERIALIZED token instead of onStable on the server?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea is that the cache is active only for the time of the initial render - Initial render is done when the app has become stable the first time.

Currently we don't want to be in the business of a generic HTTP cache past the initial render. But will decide it based on how people want to use it.

Choose a reason for hiding this comment

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

ah right, that makes sense, also means slightly less code which is always nice

@patrickmichalina
Copy link
Contributor

patrickmichalina commented Oct 10, 2017

Glad this will become a common part of the npm package..

I'd recommend some tests.. We had a large amount of bugs in our app until we wrote a few tests for the http transfer interceptors and traced the system.

https://github.com/patrickmichalina/fusebox-angular-universal-starter/blob/master/src/client/app/shared/transfer-http/transfer-http-interceptor.service.spec.ts

@Toxicable
Copy link

Toxicable commented Oct 10, 2017

@patrickmichalina We don't currently have a testing suite setup but once we do all modules will have tests added.
A testing setup will be added soon

@MarkPieszak MarkPieszak added the action: merge PR author is ready for this to merge label Oct 10, 2017
@vikerman
Copy link
Contributor Author

vikerman commented Oct 11, 2017

@patrickmichalina - Totally agreed on tests. I am in the process of setting up the tests in the CI - But wanted to get this out meanwhile.

The tests are in here when I created this PR originally for angular/angular - But we decided the http cache was too experimental to put it in core right now - vikerman/angular@3e2979e#diff-2fe0b6298256d163bcf56eb631187740 . I will get the tests ported in here.

@vikerman vikerman merged commit 23a89ec into angular:master Oct 11, 2017
@naveedahmed1
Copy link

Is it available for aspnetcore-engine as well?

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge PR author is ready for this to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants