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

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

Introduction

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

Prototype

public void setMaxCacheEntries(int maxCacheEntries) 

Source Link

Document

Sets the maximum number of cache entries the cache will retain.

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);/* w  ww  .j  a v  a2  s. 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();
}