Two approaches to using Polly's cache policy with HttpClientFactory in .NET are compared. The first integrates the cache policy via PolicySelector on the HttpClientFactory, requiring HttpRequestMessage with a Polly context key instead of the simpler GetAsync. The second bypasses the HttpClientFactory for caching by injecting the policy registry directly into the controller and calling cachePolicy.ExecuteAsync() wrapping the httpClient.GetAsync() call. Both achieve the same result, but the author prefers the first approach for consistency with other Polly policies across the application.

4m read timeFrom nodogmablog.bryanhogan.net
Post cover image