Interface ApacheHttpClient5Cache


@Beta public interface ApacheHttpClient5Cache
Provides caching functionality to the HttpClient5Accessor.

A default implementation of this interface can be instantiated by using the ApacheHttpClient5CacheBuilder.

Since:
4.20.0
  • Field Details

    • DISABLED

      @Beta @Nonnull static final ApacheHttpClient5Cache DISABLED
      Constant implementation of with disabled the cache logic. Useful for testing and troubleshooting. Don't use in production.
  • Method Details

    • newDefaultCache

      @Nonnull static ApacheHttpClient5Cache newDefaultCache(@Nonnull Duration cacheDuration)
      Creates a new HttpClient5Cache with the given cacheDuration.
      Parameters:
      cacheDuration - The duration for which HttpClient instances will be cached.
      Returns:
      A new HttpClient5Cache instance.
    • tryGetHttpClient

      @Nonnull io.vavr.control.Try<org.apache.hc.client5.http.classic.HttpClient> tryGetHttpClient(@Nonnull HttpDestinationProperties destination, @Nonnull ApacheHttpClient5Factory httpClientFactory)
      Gets the HttpClient for the given Destination from this cache.

      If there is no HttpClient for destination it is created by using the HttpClient5Factory.

      Parameters:
      destination - The Destination to get the HttpClient for.
      httpClientFactory - The HttpClient5Factory used to create a new HttpClient if no cached one can be found.
      Returns:
      The cached HttpClient for the given Destination.
      Throws:
      HttpClientInstantiationException - If there is an issue while retrieving the HttpClient.
    • tryGetHttpClient

      @Nonnull io.vavr.control.Try<org.apache.hc.client5.http.classic.HttpClient> tryGetHttpClient(@Nonnull ApacheHttpClient5Factory httpClientFactory)
      Gets the non-destination-specific HttpClient from this cache.

      If there is no generic HttpClient it is created by using the HttpClient5Factory.

      Parameters:
      httpClientFactory - The HttpClient5Factory used to create a new HttpClient if no cached one can be found.
      Returns:
      The cached HttpClient.