public static org.apache.http.client.HttpClient withCaching( org.apache.http.client.HttpClient client, int maxCacheEntries, int maxObjectSizeBytes) { CacheConfig cacheConfig = new CacheConfig(); cacheConfig.setMaxCacheEntries(maxCacheEntries); cacheConfig.setMaxObjectSizeBytes(maxObjectSizeBytes); return new CachingHttpClient(client, cacheConfig); }
@Bean @Singleton public HttpClient httpClient() { HttpClient httpClient = new DefaultHttpClient(); log.info("creating cached HttpClient"); CacheConfig cacheConfig = new CacheConfig(); cacheConfig.setMaxCacheEntries(1000); cacheConfig.setMaxObjectSize(8192); HttpClient httpClientCached = new CachingHttpClient(httpClient, cacheConfig); return httpClientCached; }
/** * Constructs a storage backend using the provided Ehcache with the given configuration options, * but using an alternative cache entry serialization strategy. * * @param cache where to store cached origin responses * @param config cache storage configuration options - note that the setting for max object size * <b>will be ignored</b> and should be configured in the Ehcache instead. * @param serializer alternative serialization mechanism */ public EhcacheHttpCacheStorage( final Ehcache cache, final CacheConfig config, final HttpCacheEntrySerializer serializer) { this.cache = cache; this.maxUpdateRetries = config.getMaxUpdateRetries(); this.serializer = serializer; }