org.apache.http.impl.client.cache.CacheConfig Java Examples
The following examples show how to use
org.apache.http.impl.client.cache.CacheConfig.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MCRURIResolver.java From mycore with GNU General Public License v3.0 | 6 votes |
MCRRESTResolver() { CacheConfig cacheConfig = CacheConfig.custom() .setMaxObjectSize(MAX_OBJECT_SIZE) .setMaxCacheEntries(MAX_CACHE_ENTRIES) .build(); RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(REQUEST_TIMEOUT) .setSocketTimeout(REQUEST_TIMEOUT) .build(); this.restClient = CachingHttpClients.custom() .setCacheConfig(cacheConfig) .setDefaultRequestConfig(requestConfig) .setUserAgent(MCRHttpUtils.getHttpUserAgent()) .useSystemProperties() .build(); MCRShutdownHandler.getInstance().addCloseable(this::close); this.logger = LogManager.getLogger(); }
Example #2
Source File: FetchServlet.java From apicurio-studio with Apache License 2.0 | 6 votes |
@PostConstruct protected void postConstruct() { try { // TODO make these settings configurable!! CacheConfig cacheConfig = CacheConfig.custom() .setMaxCacheEntries(2000) .setMaxObjectSize(16384) .build(); RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(30000) .setSocketTimeout(30000) .build(); this.httpClient = CachingHttpClients.custom() .setCacheConfig(cacheConfig) .setDefaultRequestConfig(requestConfig) .build(); } catch (Exception e) { logger.error("Error creating HTTP client.", e); throw new RuntimeException(e); } }
Example #3
Source File: HttpClientFactory.java From riptide with MIT License | 6 votes |
private static HttpClientBuilder configureCaching(final Caching caching, @Nullable final Object cacheStorage) { final Heuristic heuristic = caching.getHeuristic(); final CacheConfig.Builder config = CacheConfig.custom() .setSharedCache(caching.getShared()) .setMaxObjectSize(caching.getMaxObjectSize()) .setMaxCacheEntries(caching.getMaxCacheEntries()); if (heuristic.getEnabled()) { config.setHeuristicCachingEnabled(true); config.setHeuristicCoefficient(heuristic.getCoefficient()); config.setHeuristicDefaultLifetime(heuristic.getDefaultLifeTime().to(TimeUnit.SECONDS)); } @Hack("return cast tricks classloader in case of missing httpclient-cache") CachingHttpClientBuilder builder = CachingHttpClients.custom() .setCacheConfig(config.build()) .setHttpCacheStorage((HttpCacheStorage) cacheStorage) .setCacheDir(Optional.ofNullable(caching.getDirectory()) .map(Path::toFile) .orElse(null)); return HttpClientBuilder.class.cast(builder); }
Example #4
Source File: KeySetRetriever.java From deprecated-security-advanced-modules with Apache License 2.0 | 5 votes |
KeySetRetriever(String openIdConnectEndpoint, SSLConfig sslConfig, boolean useCacheForOidConnectEndpoint) { this.openIdConnectEndpoint = openIdConnectEndpoint; this.sslConfig = sslConfig; if (useCacheForOidConnectEndpoint) { cacheConfig = CacheConfig.custom().setMaxCacheEntries(10).setMaxObjectSize(1024L * 1024L).build(); oidcHttpCacheStorage = new BasicHttpCacheStorage(cacheConfig); } }
Example #5
Source File: HttpEndpoint.java From Brutusin-RPC with Apache License 2.0 | 5 votes |
public HttpEndpoint(URI endpoint, Config cfg, HttpClientContextFactory clientContextFactory) { if (endpoint == null) { throw new IllegalArgumentException("Endpoint is required"); } if (cfg == null) { cfg = new ConfigurationBuilder().build(); } CacheConfig cacheConfig = CacheConfig.custom() .setMaxCacheEntries(cfg.getMaxCacheEntries()) .setMaxObjectSize(cfg.getMaxCacheObjectSize()) .build(); RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(1000 * cfg.getConnectTimeOutSeconds()) .setSocketTimeout(1000 * cfg.getSocketTimeOutSeconds()) .build(); PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(cfg.getMaxConections()); this.endpoint = endpoint; this.httpClient = CachingHttpClients.custom() .setCacheConfig(cacheConfig) .setDefaultRequestConfig(requestConfig) .setRetryHandler(new StandardHttpRequestRetryHandler()) .setConnectionManager(cm) .build(); this.clientContextFactory = clientContextFactory; initPingThread(cfg.getPingSeconds()); }
Example #6
Source File: HttpUtil.java From thym with Eclipse Public License 1.0 | 5 votes |
@SuppressWarnings("restriction") private static CloseableHttpClient getHttpClient(URI url){ CacheConfig cacheConfig = CacheConfig.custom() .setMaxCacheEntries(1000) .setMaxObjectSize(120*1024).setHeuristicCachingEnabled(true) .setHeuristicDefaultLifetime(TimeUnit.HOURS.toSeconds(12)) .build(); CachingHttpClientBuilder builder = CachingHttpClients.custom() .setCacheConfig(cacheConfig) .setHttpCacheStorage(new BundleHttpCacheStorage(HybridCore.getContext().getBundle())); builder = setupProxy(builder, url); return builder.build(); }
Example #7
Source File: EhcacheCacheStorage.java From esigate with Apache License 2.0 | 5 votes |
@Override public void init(Properties properties) { String cacheName = Parameters.EHCACHE_CACHE_NAME_PROPERTY.getValue(properties); String configurationFileName = Parameters.EHCACHE_CONFIGURATION_FILE_PROPERTY.getValue(properties); // Loaded from the Classpath, default will use /ehcache.xml or if not found /ehcache-failsafe.xml CacheManager cacheManager = CacheManager.create(configurationFileName); Ehcache ehcache = cacheManager.getEhcache(cacheName); if (ehcache == null) { cacheManager.addCache(cacheName); ehcache = cacheManager.getEhcache(cacheName); } CacheConfig cacheConfig = CacheConfigHelper.createCacheConfig(properties); setImpl(new EhcacheHttpCacheStorage(ehcache, cacheConfig)); }
Example #8
Source File: CacheConfigHelper.java From esigate with Apache License 2.0 | 5 votes |
public static CacheConfig createCacheConfig(Properties properties) { // Heuristic caching boolean heuristicCachingEnabled = Parameters.HEURISTIC_CACHING_ENABLED.getValue(properties); float heuristicCoefficient = Parameters.HEURISTIC_COEFFICIENT.getValue(properties); long heuristicDefaultLifetimeSecs = Parameters.HEURISTIC_DEFAULT_LIFETIME_SECS.getValue(properties); int maxCacheEntries = Parameters.MAX_CACHE_ENTRIES.getValue(properties); long maxObjectSize = Parameters.MAX_OBJECT_SIZE.getValue(properties); // Asynchronous revalidation int minAsynchronousWorkers = Parameters.MIN_ASYNCHRONOUS_WORKERS.getValue(properties); int maxAsynchronousWorkers = Parameters.MAX_ASYNCHRONOUS_WORKERS.getValue(properties); int asynchronousWorkerIdleLifetimeSecs = Parameters.ASYNCHRONOUS_WORKER_IDLE_LIFETIME_SECS.getValue(properties); int maxUpdateRetries = Parameters.MAX_UPDATE_RETRIES.getValue(properties); int revalidationQueueSize = Parameters.REVALIDATION_QUEUE_SIZE.getValue(properties); CacheConfig.Builder builder = CacheConfig.custom(); builder.setHeuristicCachingEnabled(heuristicCachingEnabled); builder.setHeuristicCoefficient(heuristicCoefficient); builder.setHeuristicDefaultLifetime(heuristicDefaultLifetimeSecs); builder.setMaxCacheEntries(maxCacheEntries); long usedMaxObjectSize = Long.MAX_VALUE; if (maxObjectSize > 0) { usedMaxObjectSize = maxObjectSize; } builder.setMaxObjectSize(usedMaxObjectSize); builder.setAsynchronousWorkersCore(minAsynchronousWorkers); builder.setAsynchronousWorkersMax(maxAsynchronousWorkers); builder.setAsynchronousWorkerIdleLifetimeSecs(asynchronousWorkerIdleLifetimeSecs); builder.setMaxUpdateRetries(maxUpdateRetries).setRevalidationQueueSize(revalidationQueueSize); builder.setSharedCache(true); return builder.build(); }
Example #9
Source File: CachingTest.java From riptide with MIT License | 4 votes |
@Bean public HttpCacheStorage publicHttpCacheStorage() { return new BasicHttpCacheStorage(CacheConfig.DEFAULT); }
Example #10
Source File: BasicCacheStorage.java From esigate with Apache License 2.0 | 4 votes |
@Override public void init(Properties properties) { CacheConfig cacheConfig = CacheConfigHelper.createCacheConfig(properties); setImpl(new BasicHttpCacheStorage(cacheConfig)); }
Example #11
Source File: ManagedCacheStorage.java From esigate with Apache License 2.0 | 4 votes |
@Override public void init(Properties properties) { CacheConfig cacheConfig = CacheConfigHelper.createCacheConfig(properties); setImpl(new ManagedHttpCacheStorage(cacheConfig)); }