public class FileCachingHttpClientBuilder extends HttpClientBuilder
HttpClient builder that supports RFC 2616 caching.
Cached content is written to disk. Special care should be taken so that multiple clients do not share a single cache directory unintentionally. This could result senstive data being available in ways it should not be.
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:
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 File |
cacheDir
Directory in which cached content will be stored.
|
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 |
|---|
FileCachingHttpClientBuilder()
Constructor.
|
FileCachingHttpClientBuilder(CachingHttpClientBuilder builder)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
decorateApacheBuilder()
Decorate the Apache builder as determined by this builder's parameters.
|
File |
getCacheDirectory()
Gets the directory in which cached content will be stored.
|
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 |
setCacheDirectory(File directory)
Sets the directory in which cached content will be stored.
|
void |
setCacheDirectory(String directoryPath)
Sets the directory in which cached content will be stored.
|
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, getSocketBufferSize, getSocketLocalAddress, getSocketTimeout, isConnectionCloseAfterResponse, isConnectionDisregardSslCertificate, isConnectionStalecheck, isHttpFollowRedirects, resetDefaults, setConnectionCloseAfterResponse, setConnectionDisregardSslCertificate, setConnectionProxyHost, setConnectionProxyPassword, setConnectionProxyPort, setConnectionProxyUsername, setConnectionStalecheck, setConnectionTimeout, setHttpContentCharSet, setHttpFollowRedirects, setSocketBufferSize, setSocketLocalAddress, setSocketLocalAddress, setSocketTimeoutprivate File cacheDir
System.getProperty("java.io.tmpdir") + File.separator + "wwwcache"private int maxCacheEntries
private long maxCacheEntrySize
public FileCachingHttpClientBuilder()
public FileCachingHttpClientBuilder(@Nonnull CachingHttpClientBuilder builder)
builder - builder of clients used to fetch data from remote serverspublic File getCacheDirectory()
public void setCacheDirectory(@Nonnull@NotEmpty String directoryPath)
directoryPath - filesystem path to the directorypublic void setCacheDirectory(@Nonnull File directory)
directory - the directorypublic 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 HttpClientBuilderException - if there is a problem decorating the Apache builderCopyright © 1999–2014. All rights reserved.