I am using spring webclient to call external APIs. I have a builder which returns webclient. My question, is that a good idea to cache the created webclient for a specific URL.Below is my code.
@Cacheable(value = "somevalue", cacheManager = "cachemnager", key = "#url")
public WebClient getWebClient(String url, Map<String, String> headers,List<ExchangeFilterFunction> filterFunctions) {
return WebClient.builder()
.baseUrl(url)
.defaultHeaders(addsome headers)
.filters(list -> list.addAll(filterFunctions))
.build();
}
Also I have to call multiple API with different url/params/headers so I have to create multiple webclient as well.