Class CacheConfig.Builder
- java.lang.Object
-
- org.apache.hc.client5.http.impl.cache.CacheConfig.Builder
-
- Enclosing class:
- CacheConfig
public static class CacheConfig.Builder extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private intasynchronousWorkersprivate booleanfreshnessCheckEnabledprivate booleanheuristicCachingEnabledprivate floatheuristicCoefficientprivate org.apache.hc.core5.util.TimeValueheuristicDefaultLifetimeprivate intmaxCacheEntriesprivate longmaxObjectSizeprivate intmaxUpdateRetriesprivate booleanneverCacheHTTP10ResponsesWithQueryprivate booleanneverCacheHTTP11ResponsesWithQueryprivate booleansharedCacheprivate booleanstaleIfErrorEnabled
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description CacheConfigbuild()CacheConfig.BuildersetAllow303Caching(boolean allow303Caching)Deprecated.Has no effect.CacheConfig.BuildersetAsynchronousWorkers(int asynchronousWorkers)Sets the maximum number of threads to allow for background revalidations due to thestale-while-revalidatedirective.CacheConfig.BuildersetFreshnessCheckEnabled(boolean freshnessCheckEnabled)CacheConfig.BuildersetHeuristicCachingEnabled(boolean heuristicCachingEnabled)Enables or disables heuristic caching.CacheConfig.BuildersetHeuristicCoefficient(float heuristicCoefficient)Sets coefficient to be used in heuristic freshness caching.CacheConfig.BuildersetHeuristicDefaultLifetime(org.apache.hc.core5.util.TimeValue heuristicDefaultLifetime)Sets default lifetime to be used if heuristic freshness calculation is not possible.CacheConfig.BuildersetMaxCacheEntries(int maxCacheEntries)Sets the maximum number of cache entries the cache will retain.CacheConfig.BuildersetMaxObjectSize(long maxObjectSize)Specifies the maximum response body size that will be eligible for caching.CacheConfig.BuildersetMaxUpdateRetries(int maxUpdateRetries)Sets the number of times to retry a cache processChallenge on failureCacheConfig.BuildersetNeverCacheHTTP10ResponsesWithQueryString(boolean neverCacheHTTP10ResponsesWithQuery)Sets whether the cache should never cache HTTP 1.0 responses with a query string or not.CacheConfig.BuildersetNeverCacheHTTP11ResponsesWithQueryString(boolean neverCacheHTTP11ResponsesWithQuery)Sets the flag indicating whether HTTP/1.1 responses with a query string should never be cached.CacheConfig.BuildersetSharedCache(boolean sharedCache)Sets whether the cache should behave as a shared cache or not.CacheConfig.BuildersetStaleIfErrorEnabled(boolean enabled)Enables or disables the stale-if-error cache directive.CacheConfig.BuildersetWeakETagOnPutDeleteAllowed(boolean weakETagOnPutDeleteAllowed)Deprecated.No longer applicable.
-
-
-
Field Detail
-
maxObjectSize
private long maxObjectSize
-
maxCacheEntries
private int maxCacheEntries
-
maxUpdateRetries
private int maxUpdateRetries
-
heuristicCachingEnabled
private boolean heuristicCachingEnabled
-
heuristicCoefficient
private float heuristicCoefficient
-
heuristicDefaultLifetime
private org.apache.hc.core5.util.TimeValue heuristicDefaultLifetime
-
sharedCache
private boolean sharedCache
-
freshnessCheckEnabled
private boolean freshnessCheckEnabled
-
asynchronousWorkers
private int asynchronousWorkers
-
neverCacheHTTP10ResponsesWithQuery
private boolean neverCacheHTTP10ResponsesWithQuery
-
neverCacheHTTP11ResponsesWithQuery
private boolean neverCacheHTTP11ResponsesWithQuery
-
staleIfErrorEnabled
private boolean staleIfErrorEnabled
-
-
Method Detail
-
setMaxObjectSize
public CacheConfig.Builder setMaxObjectSize(long maxObjectSize)
Specifies the maximum response body size that will be eligible for caching.- Parameters:
maxObjectSize- size in bytes- Returns:
- this instance.
-
setMaxCacheEntries
public CacheConfig.Builder setMaxCacheEntries(int maxCacheEntries)
Sets the maximum number of cache entries the cache will retain.- Returns:
- this instance.
-
setMaxUpdateRetries
public CacheConfig.Builder setMaxUpdateRetries(int maxUpdateRetries)
Sets the number of times to retry a cache processChallenge on failure- Returns:
- this instance.
-
setAllow303Caching
@Deprecated public CacheConfig.Builder setAllow303Caching(boolean allow303Caching)
Deprecated.Has no effect. Do not use.- Returns:
- this instance.
-
setWeakETagOnPutDeleteAllowed
@Deprecated public CacheConfig.Builder setWeakETagOnPutDeleteAllowed(boolean weakETagOnPutDeleteAllowed)
Deprecated.No longer applicable. Do not use.- Returns:
- this instance.
-
setHeuristicCachingEnabled
public CacheConfig.Builder setHeuristicCachingEnabled(boolean heuristicCachingEnabled)
Enables or disables heuristic caching.- Parameters:
heuristicCachingEnabled- should betrueto permit heuristic caching,falseto enable it.- Returns:
- this instance.
-
setHeuristicCoefficient
public CacheConfig.Builder setHeuristicCoefficient(float heuristicCoefficient)
Sets coefficient to be used in heuristic freshness caching. This is interpreted as the fraction of the time between theLast-ModifiedandDateheaders of a cached response during which the cached response will be considered heuristically fresh.- Parameters:
heuristicCoefficient- should be between0.0and1.0.- Returns:
- this instance.
-
setHeuristicDefaultLifetime
public CacheConfig.Builder setHeuristicDefaultLifetime(org.apache.hc.core5.util.TimeValue heuristicDefaultLifetime)
Sets default lifetime to be used if heuristic freshness calculation is not possible. Explicit cache control directives on either the request or origin response will override this, as will the heuristicLast-Modifiedfreshness calculation if it is available.- Parameters:
heuristicDefaultLifetime- is the number to consider a cache-eligible response fresh in the absence of other information. Set this to0to disable this style of heuristic caching.- Returns:
- this instance.
-
setSharedCache
public CacheConfig.Builder setSharedCache(boolean sharedCache)
Sets whether the cache should behave as a shared cache or not.- Parameters:
sharedCache- true to behave as a shared cache, false to behave as a non-shared (private) cache. To have the cache behave like a browser cache, you want to set this tofalse.- Returns:
- this instance.
-
setAsynchronousWorkers
public CacheConfig.Builder setAsynchronousWorkers(int asynchronousWorkers)
Sets the maximum number of threads to allow for background revalidations due to thestale-while-revalidatedirective.- Parameters:
asynchronousWorkers- number of threads; a value of 0 disables background revalidations.- Returns:
- this instance.
-
setNeverCacheHTTP10ResponsesWithQueryString
public CacheConfig.Builder setNeverCacheHTTP10ResponsesWithQueryString(boolean neverCacheHTTP10ResponsesWithQuery)
Sets whether the cache should never cache HTTP 1.0 responses with a query string or not.- Parameters:
neverCacheHTTP10ResponsesWithQuery- true to never cache responses with a query string, false to cache if explicit cache headers are found. Set this totrueto better emulate IE, which also never caches responses, regardless of what caching headers may be present.- Returns:
- this instance.
-
setStaleIfErrorEnabled
public CacheConfig.Builder setStaleIfErrorEnabled(boolean enabled)
Enables or disables the stale-if-error cache directive. If this option is enabled, cached responses that have become stale due to an error (such as a server error or a network failure) will be returned instead of generating a new request. This can help to reduce the load on the origin server and improve performance.By default, the stale-if-error directive is disabled.
- Parameters:
enabled- a boolean value indicating whether the stale-if-error directive should be enabled.- Returns:
- this instance.
-
setFreshnessCheckEnabled
public CacheConfig.Builder setFreshnessCheckEnabled(boolean freshnessCheckEnabled)
-
setNeverCacheHTTP11ResponsesWithQueryString
public CacheConfig.Builder setNeverCacheHTTP11ResponsesWithQueryString(boolean neverCacheHTTP11ResponsesWithQuery)
Sets the flag indicating whether HTTP/1.1 responses with a query string should never be cached.- Parameters:
neverCacheHTTP11ResponsesWithQuery- whether to never cache HTTP/1.1 responses with a query string- Returns:
- this instance.
-
build
public CacheConfig build()
-
-