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

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

Introduction

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

Prototype

public void setHeuristicCoefficient(float heuristicCoefficient) 

Source Link

Document

Sets coefficient to be used in heuristic freshness caching.

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 va2s .  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();
}