public class InMemoryCachingHttpClientBuilder extends HttpClientBuilder
HttpClient
builder 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 maxCacheEntries
and maxCacheEntrySize
appropriately 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:
HttpClientBuilder
.
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.
Modifier and Type | Field and Description |
---|---|
private int |
maxCacheEntries
The maximum number of cached responses.
|
private long |
maxCacheEntrySize
The maximum response body size, in bytes, that will be eligible for caching.
|
Constructor and Description |
---|
InMemoryCachingHttpClientBuilder()
Constructor.
|
InMemoryCachingHttpClientBuilder(org.apache.http.impl.client.cache.CachingHttpClientBuilder builder)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
decorateApacheBuilder()
Decorate the Apache builder as determined by this builder's parameters.
|
int |
getMaxCacheEntries()
Gets the maximum number of cached responses.
|
long |
getMaxCacheEntrySize()
Gets the maximum response body size, in bytes, that will be eligible for caching.
|
void |
setMaxCacheEntries(int maxEntries)
Sets the maximum number of cached responses.
|
void |
setMaxCacheEntrySize(long size)
Sets the maximum response body size, in bytes, that will be eligible for caching.
|
buildClient, getApacheBuilder, getConnectionProxyHost, getConnectionProxyPassword, getConnectionProxyPort, getConnectionProxyUsername, getConnectionTimeout, getHttpContentCharSet, getHttpRequestRetryHandler, getSocketBufferSize, getSocketLocalAddress, getSocketTimeout, getTLSSocketFactory, getUserAgent, isConnectionCloseAfterResponse, isConnectionDisregardTLSCertificate, isConnectionStalecheck, isHttpFollowRedirects, resetDefaults, setConnectionCloseAfterResponse, setConnectionDisregardTLSCertificate, setConnectionProxyHost, setConnectionProxyPassword, setConnectionProxyPort, setConnectionProxyUsername, setConnectionStalecheck, setConnectionTimeout, setHttpContentCharSet, setHttpFollowRedirects, setHttpRequestRetryHandler, setSocketBufferSize, setSocketLocalAddress, setSocketLocalAddress, setSocketTimeout, setTLSSocketFactory, setUserAgent
private int maxCacheEntries
private long maxCacheEntrySize
public InMemoryCachingHttpClientBuilder()
public InMemoryCachingHttpClientBuilder(@Nonnull org.apache.http.impl.client.cache.CachingHttpClientBuilder builder)
builder
- builder of clients used to fetch data from remote serverspublic int getMaxCacheEntries()
public void setMaxCacheEntries(int maxEntries)
maxEntries
- maximum number of cached responses, must be greater than zeropublic long getMaxCacheEntrySize()
public void setMaxCacheEntrySize(long size)
size
- maximum response body size that will be eligible for caching, must be greater than zeroprotected void decorateApacheBuilder() throws Exception
decorateApacheBuilder
in class HttpClientBuilder
Exception
- if there is a problem decorating the Apache builderCopyright © 1999–2018. All rights reserved.