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;








0















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.











share|improve this question

















  • 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 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





    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

















0















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.











share|improve this question

















  • 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 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





    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













0












0








0








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.











share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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





    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





    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 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





    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












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
);



);













draft saved

draft discarded


















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















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved