类org.apache.http.impl.client.cache.CacheConfig源码实例Demo

下面列出了怎么用org.apache.http.impl.client.cache.CacheConfig的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: mycore   文件: MCRURIResolver.java
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();
}
 
源代码2 项目: apicurio-studio   文件: FetchServlet.java
@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);
    }
}
 
源代码3 项目: riptide   文件: HttpClientFactory.java
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);
}
 
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);
	}
}
 
源代码5 项目: Brutusin-RPC   文件: HttpEndpoint.java
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());
}
 
源代码6 项目: thym   文件: HttpUtil.java
@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();
}
 
源代码7 项目: esigate   文件: EhcacheCacheStorage.java
@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));
}
 
源代码8 项目: esigate   文件: CacheConfigHelper.java
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();
    }
 
源代码9 项目: riptide   文件: CachingTest.java
@Bean
public HttpCacheStorage publicHttpCacheStorage() {
    return new BasicHttpCacheStorage(CacheConfig.DEFAULT);
}
 
源代码10 项目: esigate   文件: BasicCacheStorage.java
@Override
public void init(Properties properties) {
    CacheConfig cacheConfig = CacheConfigHelper.createCacheConfig(properties);
    setImpl(new BasicHttpCacheStorage(cacheConfig));
}
 
源代码11 项目: esigate   文件: ManagedCacheStorage.java
@Override
public void init(Properties properties) {
    CacheConfig cacheConfig = CacheConfigHelper.createCacheConfig(properties);
    setImpl(new ManagedHttpCacheStorage(cacheConfig));
}
 
 类方法
 同包方法