Example usage for org.apache.http.impl.client.cache CacheConfig.Builder setAsynchronousWorkersMax

List of usage examples for org.apache.http.impl.client.cache CacheConfig.Builder setAsynchronousWorkersMax

Introduction

In this page you can find the example usage for org.apache.http.impl.client.cache CacheConfig.Builder setAsynchronousWorkersMax.

Prototype

public void setAsynchronousWorkersMax(int max) 

Source Link

Document

Sets the maximum number of threads to allow for background revalidations due to the stale-while-revalidate directive.

Usage

From source file:org.esigate.cache.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);/*from   w w  w  . j a v  a 2s  .  c  o m*/
    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();
}