Does the cached HttpClient created from HttpClientFactory have the DNS update issue?Should I cache and reuse HttpClient created from HttpClientFactory?Do HttpClient and HttpClientHandler have to be disposed?Is async HttpClient from .Net 4.5 a bad choice for intensive load applications?Static HttpClient Seems to sometimes cache redirectDoes the HTTPCientFactory in asp.net core keep the connection alive even after the request is completed like HttpClient in .net FrameworkShould HttpClient instances created by HttpClientFactory be disposed?How to define a HttpClientHandler for named HttpClient using HttpClientFactoryUse HttpClientFactory from .NET 4.6.2How to configure web proxy for HttpClient created directly via HttpClientFactory?Create default HttpClientFactory for integration testShould I cache and reuse HttpClient created from HttpClientFactory?
What is going on with Captain Marvel's blood colour?
Infinite Abelian subgroup of infinite non Abelian group example
What's the point of deactivating Num Lock on login screens?
How to say in German "enjoying home comforts"
Is there a hemisphere-neutral way of specifying a season?
What mechanic is there to disable a threat instead of killing it?
Stopping power of mountain vs road bike
Arrow those variables!
Is it legal for company to use my work email to pretend I still work there?
What is the intuition behind short exact sequences of groups; in particular, what is the intuition behind group extensions?
Why doesn't H₄O²⁺ exist?
How do I write bicross product symbols in latex?
What reasons are there for a Capitalist to oppose a 100% inheritance tax?
When a company launches a new product do they "come out" with a new product or do they "come up" with a new product?
How to prevent "they're falling in love" trope
What does it mean to describe someone as a butt steak?
Blender 2.8 I can't see vertices, edges or faces in edit mode
Western buddy movie with a supernatural twist where a woman turns into an eagle at the end
Is it canonical bit space?
What exploit are these user agents trying to use?
How can I make my BBEG immortal short of making them a Lich or Vampire?
Fully-Firstable Anagram Sets
Is it inappropriate for a student to attend their mentor's dissertation defense?
Why can't we play rap on piano?
Does the cached HttpClient created from HttpClientFactory have the DNS update issue?
Should I cache and reuse HttpClient created from HttpClientFactory?Do HttpClient and HttpClientHandler have to be disposed?Is async HttpClient from .Net 4.5 a bad choice for intensive load applications?Static HttpClient Seems to sometimes cache redirectDoes the HTTPCientFactory in asp.net core keep the connection alive even after the request is completed like HttpClient in .net FrameworkShould HttpClient instances created by HttpClientFactory be disposed?How to define a HttpClientHandler for named HttpClient using HttpClientFactoryUse HttpClientFactory from .NET 4.6.2How to configure web proxy for HttpClient created directly via HttpClientFactory?Create default HttpClientFactory for integration testShould I cache and reuse HttpClient created from HttpClientFactory?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
This thread ask about if the HttpClient created by HttpClientFactory should be cached. I think the answer is no as each HttpClientFactory will existing pool of HttpClientHandler.
But my question is what happen if it is cached and reuse. Does it still have the DNS update problem?
According to Steve Gordon's An Introduction to HttpClientFactory,
Any clients depending on the original handler chain can continue using it without any issues.
I think it means the cached HttpClient will continue use the same HttpClientHandler even after the 2 mins and it won't do the DNS update. If that is the case, the HttpClient should not be cached and should use the HttpClientFactory.CreateClient all the time.
ASP.NET Core doc just says it does not need to keep a single instance, but it does not tell the consequence if a single instance is kept.
Keeping a single HttpClient instance alive for a long duration is a common pattern used before the inception of IHttpClientFactory. This pattern becomes unnecessary after migrating to IHttpClientFactory.
.net-core dotnet-httpclient httpclientfactory
add a comment |
This thread ask about if the HttpClient created by HttpClientFactory should be cached. I think the answer is no as each HttpClientFactory will existing pool of HttpClientHandler.
But my question is what happen if it is cached and reuse. Does it still have the DNS update problem?
According to Steve Gordon's An Introduction to HttpClientFactory,
Any clients depending on the original handler chain can continue using it without any issues.
I think it means the cached HttpClient will continue use the same HttpClientHandler even after the 2 mins and it won't do the DNS update. If that is the case, the HttpClient should not be cached and should use the HttpClientFactory.CreateClient all the time.
ASP.NET Core doc just says it does not need to keep a single instance, but it does not tell the consequence if a single instance is kept.
Keeping a single HttpClient instance alive for a long duration is a common pattern used before the inception of IHttpClientFactory. This pattern becomes unnecessary after migrating to IHttpClientFactory.
.net-core dotnet-httpclient httpclientfactory
1
I suspect that by "cached" you mean "keep in a field for long" ? Then yes, and that's what the answers, articles and docs say. It's the handlers that get cached in a connection pool. Each client will get a handler from that pool. When the client gets disposed, the handler goes back to the pool and reused. When the 2 minutes pass, the handler is evicted and a new one created.
– Panagiotis Kanavos
Mar 8 at 9:29
BTW that's why the articles don't say "cached" when talking about the HttpClient instance. Caching implies temporary storage and eviction and HttpClientFactory uses an actual cache for the handlers. If you use dependency injection though you won't have to worry about any of these things
– Panagiotis Kanavos
Mar 8 at 9:33
Very detailed discussion of the disposal questions here: stevejgordon.co.uk/… . I believe you need to obtain a newHttpClient
each time fromHttpClientFactory
, to avoid the stale DNS issues. Long-duration caching anHttpClient
obtained from HCF will leave that client vulnerable to stale DNS, I believe.
– mountain traveller
Mar 8 at 17:36
1
I do read Steve Gordon's article. The MyGitHubClient keeps the HttpClient as private member and that's what I don't understand why it does it. But I just find out this comment stevejgordon.co.uk/… where Steve said "When creating these HttpClient based services which have HttpClient injected they should be registered as transient with DI." As it is transient, it's short-lived and can only be used directly in transient style classes such as controllers.
– kklo
Mar 8 at 18:20
add a comment |
This thread ask about if the HttpClient created by HttpClientFactory should be cached. I think the answer is no as each HttpClientFactory will existing pool of HttpClientHandler.
But my question is what happen if it is cached and reuse. Does it still have the DNS update problem?
According to Steve Gordon's An Introduction to HttpClientFactory,
Any clients depending on the original handler chain can continue using it without any issues.
I think it means the cached HttpClient will continue use the same HttpClientHandler even after the 2 mins and it won't do the DNS update. If that is the case, the HttpClient should not be cached and should use the HttpClientFactory.CreateClient all the time.
ASP.NET Core doc just says it does not need to keep a single instance, but it does not tell the consequence if a single instance is kept.
Keeping a single HttpClient instance alive for a long duration is a common pattern used before the inception of IHttpClientFactory. This pattern becomes unnecessary after migrating to IHttpClientFactory.
.net-core dotnet-httpclient httpclientfactory
This thread ask about if the HttpClient created by HttpClientFactory should be cached. I think the answer is no as each HttpClientFactory will existing pool of HttpClientHandler.
But my question is what happen if it is cached and reuse. Does it still have the DNS update problem?
According to Steve Gordon's An Introduction to HttpClientFactory,
Any clients depending on the original handler chain can continue using it without any issues.
I think it means the cached HttpClient will continue use the same HttpClientHandler even after the 2 mins and it won't do the DNS update. If that is the case, the HttpClient should not be cached and should use the HttpClientFactory.CreateClient all the time.
ASP.NET Core doc just says it does not need to keep a single instance, but it does not tell the consequence if a single instance is kept.
Keeping a single HttpClient instance alive for a long duration is a common pattern used before the inception of IHttpClientFactory. This pattern becomes unnecessary after migrating to IHttpClientFactory.
.net-core dotnet-httpclient httpclientfactory
.net-core dotnet-httpclient httpclientfactory
asked Mar 8 at 0:02
kklokklo
946
946
1
I suspect that by "cached" you mean "keep in a field for long" ? Then yes, and that's what the answers, articles and docs say. It's the handlers that get cached in a connection pool. Each client will get a handler from that pool. When the client gets disposed, the handler goes back to the pool and reused. When the 2 minutes pass, the handler is evicted and a new one created.
– Panagiotis Kanavos
Mar 8 at 9:29
BTW that's why the articles don't say "cached" when talking about the HttpClient instance. Caching implies temporary storage and eviction and HttpClientFactory uses an actual cache for the handlers. If you use dependency injection though you won't have to worry about any of these things
– Panagiotis Kanavos
Mar 8 at 9:33
Very detailed discussion of the disposal questions here: stevejgordon.co.uk/… . I believe you need to obtain a newHttpClient
each time fromHttpClientFactory
, to avoid the stale DNS issues. Long-duration caching anHttpClient
obtained from HCF will leave that client vulnerable to stale DNS, I believe.
– mountain traveller
Mar 8 at 17:36
1
I do read Steve Gordon's article. The MyGitHubClient keeps the HttpClient as private member and that's what I don't understand why it does it. But I just find out this comment stevejgordon.co.uk/… where Steve said "When creating these HttpClient based services which have HttpClient injected they should be registered as transient with DI." As it is transient, it's short-lived and can only be used directly in transient style classes such as controllers.
– kklo
Mar 8 at 18:20
add a comment |
1
I suspect that by "cached" you mean "keep in a field for long" ? Then yes, and that's what the answers, articles and docs say. It's the handlers that get cached in a connection pool. Each client will get a handler from that pool. When the client gets disposed, the handler goes back to the pool and reused. When the 2 minutes pass, the handler is evicted and a new one created.
– Panagiotis Kanavos
Mar 8 at 9:29
BTW that's why the articles don't say "cached" when talking about the HttpClient instance. Caching implies temporary storage and eviction and HttpClientFactory uses an actual cache for the handlers. If you use dependency injection though you won't have to worry about any of these things
– Panagiotis Kanavos
Mar 8 at 9:33
Very detailed discussion of the disposal questions here: stevejgordon.co.uk/… . I believe you need to obtain a newHttpClient
each time fromHttpClientFactory
, to avoid the stale DNS issues. Long-duration caching anHttpClient
obtained from HCF will leave that client vulnerable to stale DNS, I believe.
– mountain traveller
Mar 8 at 17:36
1
I do read Steve Gordon's article. The MyGitHubClient keeps the HttpClient as private member and that's what I don't understand why it does it. But I just find out this comment stevejgordon.co.uk/… where Steve said "When creating these HttpClient based services which have HttpClient injected they should be registered as transient with DI." As it is transient, it's short-lived and can only be used directly in transient style classes such as controllers.
– kklo
Mar 8 at 18:20
1
1
I suspect that by "cached" you mean "keep in a field for long" ? Then yes, and that's what the answers, articles and docs say. It's the handlers that get cached in a connection pool. Each client will get a handler from that pool. When the client gets disposed, the handler goes back to the pool and reused. When the 2 minutes pass, the handler is evicted and a new one created.
– Panagiotis Kanavos
Mar 8 at 9:29
I suspect that by "cached" you mean "keep in a field for long" ? Then yes, and that's what the answers, articles and docs say. It's the handlers that get cached in a connection pool. Each client will get a handler from that pool. When the client gets disposed, the handler goes back to the pool and reused. When the 2 minutes pass, the handler is evicted and a new one created.
– Panagiotis Kanavos
Mar 8 at 9:29
BTW that's why the articles don't say "cached" when talking about the HttpClient instance. Caching implies temporary storage and eviction and HttpClientFactory uses an actual cache for the handlers. If you use dependency injection though you won't have to worry about any of these things
– Panagiotis Kanavos
Mar 8 at 9:33
BTW that's why the articles don't say "cached" when talking about the HttpClient instance. Caching implies temporary storage and eviction and HttpClientFactory uses an actual cache for the handlers. If you use dependency injection though you won't have to worry about any of these things
– Panagiotis Kanavos
Mar 8 at 9:33
Very detailed discussion of the disposal questions here: stevejgordon.co.uk/… . I believe you need to obtain a new
HttpClient
each time from HttpClientFactory
, to avoid the stale DNS issues. Long-duration caching an HttpClient
obtained from HCF will leave that client vulnerable to stale DNS, I believe.– mountain traveller
Mar 8 at 17:36
Very detailed discussion of the disposal questions here: stevejgordon.co.uk/… . I believe you need to obtain a new
HttpClient
each time from HttpClientFactory
, to avoid the stale DNS issues. Long-duration caching an HttpClient
obtained from HCF will leave that client vulnerable to stale DNS, I believe.– mountain traveller
Mar 8 at 17:36
1
1
I do read Steve Gordon's article. The MyGitHubClient keeps the HttpClient as private member and that's what I don't understand why it does it. But I just find out this comment stevejgordon.co.uk/… where Steve said "When creating these HttpClient based services which have HttpClient injected they should be registered as transient with DI." As it is transient, it's short-lived and can only be used directly in transient style classes such as controllers.
– kklo
Mar 8 at 18:20
I do read Steve Gordon's article. The MyGitHubClient keeps the HttpClient as private member and that's what I don't understand why it does it. But I just find out this comment stevejgordon.co.uk/… where Steve said "When creating these HttpClient based services which have HttpClient injected they should be registered as transient with DI." As it is transient, it's short-lived and can only be used directly in transient style classes such as controllers.
– kklo
Mar 8 at 18:20
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054772%2fdoes-the-cached-httpclient-created-from-httpclientfactory-have-the-dns-update-is%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054772%2fdoes-the-cached-httpclient-created-from-httpclientfactory-have-the-dns-update-is%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I suspect that by "cached" you mean "keep in a field for long" ? Then yes, and that's what the answers, articles and docs say. It's the handlers that get cached in a connection pool. Each client will get a handler from that pool. When the client gets disposed, the handler goes back to the pool and reused. When the 2 minutes pass, the handler is evicted and a new one created.
– Panagiotis Kanavos
Mar 8 at 9:29
BTW that's why the articles don't say "cached" when talking about the HttpClient instance. Caching implies temporary storage and eviction and HttpClientFactory uses an actual cache for the handlers. If you use dependency injection though you won't have to worry about any of these things
– Panagiotis Kanavos
Mar 8 at 9:33
Very detailed discussion of the disposal questions here: stevejgordon.co.uk/… . I believe you need to obtain a new
HttpClient
each time fromHttpClientFactory
, to avoid the stale DNS issues. Long-duration caching anHttpClient
obtained from HCF will leave that client vulnerable to stale DNS, I believe.– mountain traveller
Mar 8 at 17:36
1
I do read Steve Gordon's article. The MyGitHubClient keeps the HttpClient as private member and that's what I don't understand why it does it. But I just find out this comment stevejgordon.co.uk/… where Steve said "When creating these HttpClient based services which have HttpClient injected they should be registered as transient with DI." As it is transient, it's short-lived and can only be used directly in transient style classes such as controllers.
– kklo
Mar 8 at 18:20