Class InMemoryCachingHttpClientBuilder
- java.lang.Object
-
- net.shibboleth.utilities.java.support.httpclient.HttpClientBuilder
-
- net.shibboleth.utilities.java.support.httpclient.InMemoryCachingHttpClientBuilder
-
public class InMemoryCachingHttpClientBuilder extends HttpClientBuilder
AnHttpClientbuilder that supports RFC 2616 caching.This client will cache information retrieved from the remote server in memory. The backing store does not perform any resource management (e.g., removing content that has nominally expired) so, special care must be taken to tune the
maxCacheEntriesandmaxCacheEntrySizeappropriately so that the system's memory is not fully consumed.When using the single-arg constructor variant to wrap an existing instance of
CachingHttpClientBuilder, there are several caveats of which to be aware:-
Several important non-caching-specific caveats are enumerated in this class's superclass
HttpClientBuilder. -
Instances of the following which are set as the default instance on the Apache builder will be
unconditionally overwritten by this builder when
HttpClientBuilder.buildClient()is called:CacheConfig
This is due to the unfortunate fact that the Apache builder does not currently provide accessor methods to obtain the default instances currently set on the builder. Therefore, if you need to set any default cache config parameters which are not exposed by this builder, then you must use the Apache builder directly and may not use this builder.
-
Several important non-caching-specific caveats are enumerated in this class's superclass
-
-
Field Summary
Fields Modifier and Type Field Description private intmaxCacheEntriesThe maximum number of cached responses.private longmaxCacheEntrySizeThe maximum response body size, in bytes, that will be eligible for caching.
-
Constructor Summary
Constructors Constructor Description InMemoryCachingHttpClientBuilder()Constructor.InMemoryCachingHttpClientBuilder(org.apache.http.impl.client.cache.CachingHttpClientBuilder builder)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddecorateApacheBuilder()Decorate the Apache builder as determined by this builder's parameters.intgetMaxCacheEntries()Gets the maximum number of cached responses.longgetMaxCacheEntrySize()Gets the maximum response body size, in bytes, that will be eligible for caching.voidsetMaxCacheEntries(int maxEntries)Sets the maximum number of cached responses.voidsetMaxCacheEntrySize(long size)Sets the maximum response body size, in bytes, that will be eligible for caching.-
Methods inherited from class net.shibboleth.utilities.java.support.httpclient.HttpClientBuilder
buildClient, getApacheBuilder, getConnectionProxyHost, getConnectionProxyPassword, getConnectionProxyPort, getConnectionProxyUsername, getConnectionRequestTimeout, getConnectionTimeout, getFirstRequestInterceptors, getFirstResponseInterceptors, getHttpContentCharSet, getHttpRequestRetryHandler, getLastRequestInterceptors, getLastResponseInterceptors, getMaxConnectionsPerRoute, getMaxConnectionsTotal, getServiceUnavailableRetryHandler, getSocketBufferSize, getSocketLocalAddress, getSocketTimeout, getStaticContextHandlers, getTLSSocketFactory, getUserAgent, isConnectionCloseAfterResponse, isConnectionDisregardTLSCertificate, isConnectionStalecheck, isConnectionStaleCheck, isDisableAuthCaching, isDisableAutomaticRetries, isDisableConnectionState, isDisableContentCompression, isDisableCookieManagement, isDisableRedirectHandling, isHttpFollowRedirects, isUseSystemProperties, resetDefaults, setConnectionCloseAfterResponse, setConnectionDisregardTLSCertificate, setConnectionProxyHost, setConnectionProxyPassword, setConnectionProxyPort, setConnectionProxyUsername, setConnectionRequestTimeout, setConnectionStalecheck, setConnectionStaleCheck, setConnectionTimeout, setDisableAuthCaching, setDisableAutomaticRetries, setDisableConnectionState, setDisableContentCompression, setDisableCookieManagement, setDisableRedirectHandling, setFirstRequestInterceptors, setFirstResponseInterceptors, setHttpContentCharSet, setHttpFollowRedirects, setHttpRequestRetryHandler, setLastRequestInterceptors, setLastResponseInterceptors, setMaxConnectionsPerRoute, setMaxConnectionsTotal, setServiceUnavailableRetryHandler, setSocketBufferSize, setSocketLocalAddress, setSocketLocalAddress, setSocketTimeout, setStaticContextHandlers, setTLSSocketFactory, setUserAgent, setUseSystemProperties
-
-
-
-
Constructor Detail
-
InMemoryCachingHttpClientBuilder
public InMemoryCachingHttpClientBuilder()
Constructor.
-
InMemoryCachingHttpClientBuilder
public InMemoryCachingHttpClientBuilder(@Nonnull org.apache.http.impl.client.cache.CachingHttpClientBuilder builder)Constructor.- Parameters:
builder- builder of clients used to fetch data from remote servers
-
-
Method Detail
-
getMaxCacheEntries
public int getMaxCacheEntries()
Gets the maximum number of cached responses.- Returns:
- maximum number of cached responses
-
setMaxCacheEntries
public void setMaxCacheEntries(int maxEntries)
Sets the maximum number of cached responses.- Parameters:
maxEntries- maximum number of cached responses, must be greater than zero
-
getMaxCacheEntrySize
public long getMaxCacheEntrySize()
Gets the maximum response body size, in bytes, that will be eligible for caching.- Returns:
- maximum response body size that will be eligible for caching
-
setMaxCacheEntrySize
public void setMaxCacheEntrySize(long size)
Sets the maximum response body size, in bytes, that will be eligible for caching.- Parameters:
size- maximum response body size that will be eligible for caching, must be greater than zero
-
decorateApacheBuilder
protected void decorateApacheBuilder() throws ExceptionDecorate the Apache builder as determined by this builder's parameters. Subclasses will likely add additional decoration.- Overrides:
decorateApacheBuilderin classHttpClientBuilder- Throws:
Exception- if there is a problem decorating the Apache builder
-
-