Class CacheValidityPolicy
java.lang.Object
org.apache.hc.client5.http.impl.cache.CacheValidityPolicy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final floatprivate final org.apache.hc.core5.util.TimeValueprivate static final org.slf4j.Loggerprivate final booleanprivate final boolean -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor for CacheValidityPolicy.CacheValidityPolicy(CacheConfig config) Constructs a CacheValidityPolicy with the provided CacheConfig. -
Method Summary
Modifier and TypeMethodDescription(package private) longgetAgeValue(HttpCacheEntry entry) Extracts and processes the Age value from an HttpCacheEntry by tokenizing the Age header value.(package private) org.apache.hc.core5.util.TimeValuegetApparentAge(HttpCacheEntry entry) (package private) org.apache.hc.core5.util.TimeValue(package private) org.apache.hc.core5.util.TimeValueorg.apache.hc.core5.util.TimeValuegetCurrentAge(HttpCacheEntry entry, Instant now) org.apache.hc.core5.util.TimeValuegetFreshnessLifetime(ResponseCacheControl responseCacheControl, HttpCacheEntry entry) Calculate the freshness lifetime of a response based on the provided cache control and cache entry.(package private) org.apache.hc.core5.util.TimeValue(package private) org.apache.hc.core5.util.TimeValuegetResidentTime(HttpCacheEntry entry, Instant now) (package private) org.apache.hc.core5.util.TimeValuegetResponseDelay(HttpCacheEntry entry)
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
useHeuristicCaching
private final boolean useHeuristicCaching -
heuristicCoefficient
private final float heuristicCoefficient -
heuristicDefaultLifetime
private final org.apache.hc.core5.util.TimeValue heuristicDefaultLifetime
-
-
Constructor Details
-
CacheValidityPolicy
CacheValidityPolicy(CacheConfig config) Constructs a CacheValidityPolicy with the provided CacheConfig. If the config is null, it will use default heuristic coefficient and default heuristic lifetime from CacheConfig.DEFAULT.- Parameters:
config- The CacheConfig to use for this CacheValidityPolicy. If null, default values are used.
-
CacheValidityPolicy
CacheValidityPolicy()Default constructor for CacheValidityPolicy. Initializes the policy with default values.
-
-
Method Details
-
getCurrentAge
-
getFreshnessLifetime
public org.apache.hc.core5.util.TimeValue getFreshnessLifetime(ResponseCacheControl responseCacheControl, HttpCacheEntry entry) Calculate the freshness lifetime of a response based on the provided cache control and cache entry.- If the cache is shared and the s-maxage response directive is present, use its value.
- If the max-age response directive is present, use its value.
- If the Expires response header field is present, use its value minus the value of the Date response header field.
- Otherwise, a heuristic freshness lifetime might be applicable.
- Parameters:
responseCacheControl- the cache control directives associated with the response.entry- the cache entry associated with the response.- Returns:
- the calculated freshness lifetime as a
TimeValue.
-
getHeuristicFreshnessLifetime
-
getApparentAge
-
getAgeValue
Extracts and processes the Age value from an HttpCacheEntry by tokenizing the Age header value. The Age header value is interpreted as a sequence of tokens, and the first token is parsed into a number representing the age in delta-seconds. If the first token cannot be parsed into a number, the Age value is considered as invalid and this method returns 0. If the first token represents a negative number or a number that exceeds Integer.MAX_VALUE, the Age value is set to MAX_AGE (in seconds). This method uses CacheSupport.parseTokens to robustly handle the Age header value.Note: If the HttpCacheEntry contains multiple Age headers, only the first one is considered.
- Parameters:
entry- The HttpCacheEntry from which to extract the Age value.- Returns:
- The Age value in delta-seconds, or MAX_AGE in seconds if the Age value exceeds Integer.MAX_VALUE or is negative. If the Age value is invalid (cannot be parsed into a number or contains non-numeric characters), this method returns 0.
-
getCorrectedAgeValue
-
getResponseDelay
-
getCorrectedInitialAge
-
getResidentTime
-