当前位置: 首页>>代码示例>>Java>>正文


Java CacheConfig类代码示例

本文整理汇总了Java中org.apache.http.impl.client.cache.CacheConfig的典型用法代码示例。如果您正苦于以下问题:Java CacheConfig类的具体用法?Java CacheConfig怎么用?Java CacheConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CacheConfig类属于org.apache.http.impl.client.cache包,在下文中一共展示了CacheConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getHttpClientBuilder

import org.apache.http.impl.client.cache.CacheConfig; //导入依赖的package包/类
public static HttpClientBuilder getHttpClientBuilder() {
	// Common CacheConfig for both the JarCacheStorage and the underlying
	// BasicHttpCacheStorage
	final CacheConfig cacheConfig = CacheConfig.custom().setMaxCacheEntries(1000).setMaxObjectSize(1024 * 128)
			.build();

	RequestConfig config = RequestConfig.custom().setConnectTimeout(DEFAULT_TIMEOUT)
			.setConnectionRequestTimeout(DEFAULT_TIMEOUT).setSocketTimeout(DEFAULT_TIMEOUT).build();

	HttpClientBuilder clientBuilder = CachingHttpClientBuilder.create()
			// allow caching
			.setCacheConfig(cacheConfig)
			// Wrap the local JarCacheStorage around a BasicHttpCacheStorage
			.setHttpCacheStorage(new JarCacheStorage(null, cacheConfig, new BasicHttpCacheStorage(cacheConfig)))
			// Support compressed data
			// http://hc.apache.org/httpcomponents-client-ga/tutorial/html/httpagent.html#d5e1238
			.addInterceptorFirst(new RequestAcceptEncoding()).addInterceptorFirst(new ResponseContentEncoding())
			// use system defaults for proxy etc.
			.useSystemProperties().setDefaultRequestConfig(config);
	return clientBuilder;
}
 
开发者ID:ansell,项目名称:csvsum,代码行数:22,代码来源:JSONUtil.java

示例2: MCRRESTResolver

import org.apache.http.impl.client.cache.CacheConfig; //导入依赖的package包/类
public 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();
    String userAgent = MessageFormat
        .format("MyCoRe/{0} ({1}; java {2})", MCRCoreVersion.getCompleteVersion(), MCRConfiguration.instance()
            .getString("MCR.NameOfProject", "undefined"), System.getProperty("java.version"));
    this.restClient = CachingHttpClients.custom()
        .setCacheConfig(cacheConfig)
        .setDefaultRequestConfig(requestConfig)
        .setUserAgent(userAgent)
        .build();
    MCRShutdownHandler.getInstance().addCloseable(this::close);
    this.logger = LogManager.getLogger();
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:21,代码来源:MCRURIResolver.java

示例3: newClosableCachingHttpClient

import org.apache.http.impl.client.cache.CacheConfig; //导入依赖的package包/类
private static CloseableHttpClient newClosableCachingHttpClient(EventStoreSettings settings) {
   final CacheConfig cacheConfig = CacheConfig.custom()
         .setMaxCacheEntries(Integer.MAX_VALUE)
         .setMaxObjectSize(Integer.MAX_VALUE)
         .build();

   settings.getCacheDirectory()
         .mkdirs();

   return CachingHttpClientBuilder.create()
         .setHttpCacheStorage(new FileCacheStorage(cacheConfig, settings.getCacheDirectory()))
         .setCacheConfig(cacheConfig)
         .setDefaultRequestConfig(requestConfig(settings))
         .setDefaultCredentialsProvider(credentialsProvider(settings))
         .setRedirectStrategy(new LaxRedirectStrategy())
         .setRetryHandler(new StandardHttpRequestRetryHandler())
         .setKeepAliveStrategy(new de.qyotta.eventstore.utils.DefaultConnectionKeepAliveStrategy())
         .setConnectionManagerShared(true)

         .build();
}
 
开发者ID:Qyotta,项目名称:axon-eventstore,代码行数:22,代码来源:HttpClientFactory.java

示例4: createDefaultClient

import org.apache.http.impl.client.cache.CacheConfig; //导入依赖的package包/类
private CloseableHttpClient createDefaultClient(HttpClientConnectionManager fClientCm) {
	final CacheConfig cacheConfig = CacheConfig.custom()
			.setMaxCacheEntries(DEFAULT_CACHE_MAX_ENTRIES)
			.setMaxObjectSize(DEFAULT_CACHE_MAX_OBJ_SIZE)
			.setHeuristicCachingEnabled(true)
			.setHeuristicDefaultLifetime(DEFAULT_CACHE_TTL_IN_SECS)
			.build();
	
	final RequestConfig requestConfig = RequestConfig.custom()
			.setConnectTimeout(DEFAULT_REQUEST_CONN_TIMEOUT_IN_MS)
			.setSocketTimeout(DEFAULT_REQUEST_SOCK_TIMEOUT_IN_MS)
			.build();
	
	return CachingHttpClients.custom()
			.setCacheConfig(cacheConfig)
			.setConnectionManager(fClientCm)
			.setDefaultRequestConfig(requestConfig)
	        .build();
}
 
开发者ID:att,项目名称:dmaap-framework,代码行数:20,代码来源:SAClient.java

示例5: HttpEndpoint

import org.apache.http.impl.client.cache.CacheConfig; //导入依赖的package包/类
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());
}
 
开发者ID:brutusin,项目名称:Brutusin-RPC,代码行数:30,代码来源:HttpEndpoint.java

示例6: setUp

import org.apache.http.impl.client.cache.CacheConfig; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
    mockMemcachedClient = mock(MemcachedClientIF.class);
    mockKeyHashingScheme = mock(KeyHashingScheme.class);
    mockMemcachedCacheEntryFactory = mock(MemcachedCacheEntryFactory.class);
    mockMemcachedCacheEntry = mock(MemcachedCacheEntry.class);
    mockMemcachedCacheEntry2 = mock(MemcachedCacheEntry.class);
    mockMemcachedCacheEntry3 = mock(MemcachedCacheEntry.class);
    mockMemcachedCacheEntry4 = mock(MemcachedCacheEntry.class);
    final CacheConfig config = CacheConfig.custom().setMaxUpdateRetries(1).build();
    impl = new MemcachedHttpCacheStorage(mockMemcachedClient, config,
            mockMemcachedCacheEntryFactory, mockKeyHashingScheme);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:15,代码来源:TestMemcachedHttpCacheStorage.java

示例7: setUp

import org.apache.http.impl.client.cache.CacheConfig; //导入依赖的package包/类
@Override
@Before
public void setUp() {
    super.setUp();
    config = CacheConfig.custom().setMaxObjectSize(MAX_BYTES).build();

    if (CACHE_MANAGER.cacheExists(TEST_EHCACHE_NAME)){
        CACHE_MANAGER.removeCache(TEST_EHCACHE_NAME);
    }
    CACHE_MANAGER.addCache(TEST_EHCACHE_NAME);
    final HttpCacheStorage storage = new EhcacheHttpCacheStorage(CACHE_MANAGER.getCache(TEST_EHCACHE_NAME));
    mockBackend = EasyMock.createNiceMock(ClientExecChain.class);

    impl = new CachingExec(mockBackend, new HeapResourceFactory(), storage, config);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:16,代码来源:TestEhcacheProtocolRequirements.java

示例8: setUp

import org.apache.http.impl.client.cache.CacheConfig; //导入依赖的package包/类
@Override
public void setUp() {
    mockCache = mock(Ehcache.class);
    final CacheConfig config = CacheConfig.custom().setMaxUpdateRetries(1).build();
    mockSerializer = mock(HttpCacheEntrySerializer.class);
    impl = new EhcacheHttpCacheStorage(mockCache, config, mockSerializer);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:8,代码来源:TestEhcacheHttpCacheStorage.java

示例9: createStorage

import org.apache.http.impl.client.cache.CacheConfig; //导入依赖的package包/类
private HttpCacheStorage createStorage()
{
    CacheConfig config = new CacheConfig();
    // if max cache entries value is not present the CacheConfig's default (CacheConfig.DEFAULT_MAX_CACHE_ENTRIES = 1000) will be used
    Integer maxCacheEntries = Integer.getInteger("bitbucket.client.cache.maxentries");
    if (maxCacheEntries != null)
    {
        config.setMaxCacheEntries(maxCacheEntries);
    }
    return new BasicHttpCacheStorage(config);
}
 
开发者ID:edgehosting,项目名称:jira-dvcs-connector,代码行数:12,代码来源:HttpClientProvider.java

示例10: tex2json

import org.apache.http.impl.client.cache.CacheConfig; //导入依赖的package包/类
private static String tex2json(String tex) throws IOException {
    CachingHttpClientBuilder cachingHttpClientBuilder = CachingHttpClientBuilder.create();
    CacheConfig cacheCfg = new CacheConfig();
    cacheCfg.setMaxCacheEntries(100000);
    cacheCfg.setMaxObjectSize(8192);
    cachingHttpClientBuilder.setCacheConfig(cacheCfg);
    HttpClient client = cachingHttpClientBuilder.build();
    //HttpPost post = new HttpPost("http://localhost/convert");
    HttpPost post = new HttpPost("https://drmf-latexml.wmflabs.org");
    List<NameValuePair> nameValuePairs = new ArrayList<>(1);
    nameValuePairs.add(new BasicNameValuePair("tex",
        "$" + tex + "$"));
    //WARNING: This does not produce pmml, since there is a xstl trasformation that rewrites the output and removes pmml
//	      nameValuePairs.add(new BasicNameValuePair("profile",
//		          "mwsquery"));
    nameValuePairs.add(new BasicNameValuePair("preload",
        "mws.sty"));
    nameValuePairs.add(new BasicNameValuePair("profile",
        "math"));
    nameValuePairs.add(new BasicNameValuePair("noplane1",
        ""));
    nameValuePairs.add(new BasicNameValuePair("whatsout",
        "math"));
    post.setEntity(new UrlEncodedFormEntity(nameValuePairs, "utf-8"));
    HttpResponse response = client.execute(post);
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String line = "";
    String result = "";
    while ((line = rd.readLine()) != null) {
      result += line;
    }
    return result;
  }
 
开发者ID:ag-gipp,项目名称:mathosphere,代码行数:34,代码来源:TeX2MathML.java

示例11: getHttpClient

import org.apache.http.impl.client.cache.CacheConfig; //导入依赖的package包/类
@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();
}
 
开发者ID:eclipse,项目名称:thym,代码行数:16,代码来源:HttpUtil.java

示例12: buildClient

import org.apache.http.impl.client.cache.CacheConfig; //导入依赖的package包/类
/**
 * Builds the HTTP client to connect to the server.
 * 
 * @param trustSelfSigned <tt>true</tt> if the client should accept
 *            self-signed certificates
 * @return a new client instance
 */
private CloseableHttpClient buildClient(boolean trustSelfSigned) {
	try {
		// if required, define custom SSL context allowing self-signed certs
		SSLContext sslContext = !trustSelfSigned ? SSLContexts.createSystemDefault()
			: SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();

		// set timeouts for the HTTP client
		int globalTimeout = readFromProperty("bdTimeout", 100000);
		int connectTimeout = readFromProperty("bdConnectTimeout", globalTimeout);
		int connectionRequestTimeout = readFromProperty("bdConnectionRequestTimeout", globalTimeout);
		int socketTimeout = readFromProperty("bdSocketTimeout", globalTimeout);
		RequestConfig requestConfig = RequestConfig.copy(RequestConfig.DEFAULT).setConnectTimeout(connectTimeout)
			.setSocketTimeout(socketTimeout).setConnectionRequestTimeout(connectionRequestTimeout).build();

		// configure caching
		CacheConfig cacheConfig = CacheConfig.copy(CacheConfig.DEFAULT).setSharedCache(false).setMaxCacheEntries(1000)
			.setMaxObjectSize(2 * 1024 * 1024).build();

		// configure connection pooling
		PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(RegistryBuilder
			.<ConnectionSocketFactory> create().register("http", PlainConnectionSocketFactory.getSocketFactory())
			.register("https", new SSLConnectionSocketFactory(sslContext)).build());
		int connectionLimit = readFromProperty("bdMaxConnections", 40);
		// there's only one server to connect to, so max per route matters
		connManager.setMaxTotal(connectionLimit);
		connManager.setDefaultMaxPerRoute(connectionLimit);

		// create the HTTP client
		return CachingHttpClientBuilder.create().setCacheConfig(cacheConfig).setDefaultRequestConfig(requestConfig)
			.setConnectionManager(connManager).build();
	} catch (GeneralSecurityException e) {
		throw new InternalConfigurationException("Failed to set up SSL context", e);
	}
}
 
开发者ID:BellaDati,项目名称:belladati-sdk-java,代码行数:42,代码来源:BellaDatiClient.java

示例13: SimpleHttpClient

import org.apache.http.impl.client.cache.CacheConfig; //导入依赖的package包/类
/**
 * Creates a HTTP client.
 * 
 * @param parent
 *            Owning object. Used for logging.
 * @param maxCacheEntries
 *            the maximum number of cache entries the cache will retain. Set to 0 for no caching.
 */
public SimpleHttpClient(Object parent, int maxCacheEntries) {
    logger = Logger.getLogger(this.getClass().getName() + "-" + instanceCounter.incrementAndGet() + " ("
            + parent.getClass().getSimpleName() + ")");

    isShutdown = new AtomicBoolean();

    PoolingClientConnectionManager conman = new PoolingClientConnectionManager();
    // increase max number of connections per host and total, defaults are too low to take advantage of multiple
    // threads
    conman.setDefaultMaxPerRoute(50); // default is 2
    conman.setMaxTotal(100); // default is 20
    defaultClient = new DefaultHttpClient(conman);

    if (maxCacheEntries > 0) {
        CacheConfig cacheConfig = new CacheConfig();
        cacheConfig.setSharedCache(false);
        cacheConfig.setMaxCacheEntries(maxCacheEntries);
        cachingClient = new CachingHttpClient(defaultClient, cacheConfig);
        theClient = cachingClient;
    } else {
        cachingClient = null;
        theClient = defaultClient;
    }

    logger.info("Created");
}
 
开发者ID:fgavilondo,项目名称:neo4j-webgraph,代码行数:35,代码来源:SimpleHttpClient.java

示例14: httpClient

import org.apache.http.impl.client.cache.CacheConfig; //导入依赖的package包/类
@Bean
public CloseableHttpClient httpClient() {
    RequestConfig requestConfig = RequestConfig.custom()
        .setConnectTimeout(properties().getReadTimeout())
        .setSocketTimeout(properties().getSocketTimeout())
        .build();

    PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
    connectionManager.setMaxTotal(properties().getMaxTotalConnections());
    connectionManager.setDefaultMaxPerRoute(properties().getMaxConnectionsPerRoute());

    CacheConfig cacheConfig = CacheConfig.custom()
        .setMaxCacheEntries(properties().getMaxCacheEntries())
        .setMaxObjectSize(properties().getMaxObjectSize())
        .setHeuristicCachingEnabled(true) // important!
        .build();

    File cacheDir = new File(properties().getCacheDir());
    try {
        Files.createDirectories(cacheDir.toPath());
    } catch (IOException e) {
        log.warn("Could not create cache directory - using temp folder", e);
        try {
            cacheDir = Files.createTempDirectory("cache").toFile();
        } catch (IOException ee) {
            log.warn("Could not create temp cache directory", ee);
        }
    }

    FileResourceFactory resourceFactory = new FileResourceFactory(cacheDir);
    cacheStorage = new ManagedHttpCacheStorage(cacheConfig);

    client = CachingHttpClients.custom()
        .setCacheConfig(cacheConfig)
        .setResourceFactory(resourceFactory)
        .setHttpCacheStorage(cacheStorage)
        .setDefaultRequestConfig(requestConfig)
        .setConnectionManager(connectionManager)
        .setUserAgent(Constants.USER_AGENT)
        .build();

    return client;
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:44,代码来源:HttpClientConfiguration.java

示例15: FileCacheStorage

import org.apache.http.impl.client.cache.CacheConfig; //导入依赖的package包/类
public FileCacheStorage(final CacheConfig config, File cacheDir) {
   this.cacheDir = cacheDir;
}
 
开发者ID:Qyotta,项目名称:axon-eventstore,代码行数:4,代码来源:FileCacheStorage.java


注:本文中的org.apache.http.impl.client.cache.CacheConfig类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。