Java源码示例:org.apache.http.client.cache.HttpCacheStorage

示例1
private CloseableHttpClient createHttpClient(HttpCacheStorage httpCacheStorage) {
	HttpClientBuilder builder;

	if (httpCacheStorage != null) {
		builder = CachingHttpClients.custom().setCacheConfig(cacheConfig).setHttpCacheStorage(httpCacheStorage);
	} else {
		builder = HttpClients.custom();
	}

	builder.useSystemProperties();

	if (sslConfig != null) {
		builder.setSSLSocketFactory(sslConfig.toSSLConnectionSocketFactory());
	}

	return builder.build();
}
 
示例2
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);
}
 
示例3
private Optional<BeanReference> findCacheStorageReference(final String id, final Client client) {
    if (client.getCaching().getEnabled()) {
        return registry.findRef(id, HttpCacheStorage.class);
    } else {
        return Optional.empty();
    }
}
 
示例4
@Bean
public HttpCacheStorage publicHttpCacheStorage() {
    return new BasicHttpCacheStorage(CacheConfig.DEFAULT);
}
 
示例5
public void setImpl(HttpCacheStorage impl) {
    this.impl = impl;
}