Class AbstractHttpClientCache

java.lang.Object
com.sap.cloud.sdk.cloudplatform.connectivity.AbstractHttpClientCache
All Implemented Interfaces:
HttpClientCache
Direct Known Subclasses:
DefaultHttpClientCache

public abstract class AbstractHttpClientCache extends Object implements HttpClientCache
Provides caching functionality to the HttpClientAccessor.
  • Constructor Details

    • AbstractHttpClientCache

      public AbstractHttpClientCache()
  • Method Details

    • tryGetHttpClient

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

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

      Specified by:
      tryGetHttpClient in interface HttpClientCache
      Parameters:
      destination - The Destination to get the HttpClient for.
      httpClientFactory - The HttpClientFactory used to create a new HttpClient if no cached one can be found.
      Returns:
      A Try of the cached HttpClient for the given Destination.
    • tryGetHttpClient

      @Nonnull public io.vavr.control.Try<org.apache.http.client.HttpClient> tryGetHttpClient(@Nonnull HttpClientFactory httpClientFactory)
      Gets the non-destination-specific HttpClient from this cache.

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

      Specified by:
      tryGetHttpClient in interface HttpClientCache
      Parameters:
      httpClientFactory - The HttpClientFactory used to create a new HttpClient if no cached one can be found.
      Returns:
      A Try of the cached HttpClient.
    • getCache

      @Nonnull protected abstract io.vavr.control.Try<com.github.benmanes.caffeine.cache.Cache<CacheKey,org.apache.http.client.HttpClient>> getCache()
      Getter for the cache to be used.

      If the optional is empty a new HttpClient will be created and not cached.

      Returns:
      A Try of the cache to be used by the tryGetHttpClient(HttpDestinationProperties, HttpClientFactory) method.
      Throws:
      HttpClientInstantiationException - If there is an issue while accessing the cache.
    • getCacheKey

      @Nonnull protected abstract io.vavr.control.Try<CacheKey> getCacheKey(@Nonnull HttpDestinationProperties destination)
      Method called in the #getClient(Destination, HttpClientFactory) method to create a CacheKey for the given Destination.
      Parameters:
      destination - The destination to create a CacheKey for.
      Returns:
      A Try of the CacheKey for destination.
      Throws:
      HttpClientInstantiationException - If there is an issue while accessing the cache key.
    • getCacheKey

      @Nonnull protected abstract io.vavr.control.Try<CacheKey> getCacheKey()
      Method called in the #getClient(HttpClientFactory) method to create a CacheKey for no specific Destination.
      Returns:
      A Try of the CacheKey for a generic HttpClient.
      Throws:
      HttpClientInstantiationException - If there is an issue while accessing the cache key.