Class CacheValidityPolicy
java.lang.Object
org.apache.hc.client5.http.impl.cache.CacheValidityPolicy
- Direct Known Subclasses:
HttpByteArrayCacheEntrySerializer.NoAgeCacheValidityPolicy
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanThis matters for deciding whether the cache entry is valid to serve as a response.protected longgetAgeValue(HttpCacheEntry entry) protected org.apache.hc.core5.util.TimeValuegetApparentAge(HttpCacheEntry entry) protected org.apache.hc.core5.util.TimeValueprotected org.apache.hc.core5.util.TimeValueorg.apache.hc.core5.util.TimeValuegetCurrentAge(HttpCacheEntry entry, Instant now) org.apache.hc.core5.util.TimeValueorg.apache.hc.core5.util.TimeValuegetHeuristicFreshnessLifetime(HttpCacheEntry entry, float coefficient, org.apache.hc.core5.util.TimeValue defaultLifetime) protected longgetMaxAge(HttpCacheEntry entry) protected org.apache.hc.core5.util.TimeValuegetResidentTime(HttpCacheEntry entry, Instant now) protected org.apache.hc.core5.util.TimeValuegetResponseDelay(HttpCacheEntry entry) org.apache.hc.core5.util.TimeValuegetStaleness(HttpCacheEntry entry, Instant now) booleanhasCacheControlDirective(HttpCacheEntry entry, String directive) booleanisResponseFresh(HttpCacheEntry entry, Instant now) booleanisResponseHeuristicallyFresh(HttpCacheEntry entry, Instant now, float coefficient, org.apache.hc.core5.util.TimeValue defaultLifetime) Decides if this response is fresh enough based Last-Modified and Date, if available.booleanisRevalidatable(HttpCacheEntry entry) booleanmayReturnStaleIfError(org.apache.hc.core5.http.HttpRequest request, HttpCacheEntry entry, Instant now) private booleanmayReturnStaleIfError(org.apache.hc.core5.http.MessageHeaders headers, String name, org.apache.hc.core5.util.TimeValue staleness) booleanmayReturnStaleWhileRevalidating(HttpCacheEntry entry, Instant now) booleanmustRevalidate(HttpCacheEntry entry) booleanproxyRevalidate(HttpCacheEntry entry)
-
Field Details
-
MAX_AGE
public static final org.apache.hc.core5.util.TimeValue MAX_AGE
-
-
Constructor Details
-
CacheValidityPolicy
CacheValidityPolicy()
-
-
Method Details
-
getCurrentAge
-
getFreshnessLifetime
-
isResponseFresh
-
isResponseHeuristicallyFresh
public boolean isResponseHeuristicallyFresh(HttpCacheEntry entry, Instant now, float coefficient, org.apache.hc.core5.util.TimeValue defaultLifetime) Decides if this response is fresh enough based Last-Modified and Date, if available. This entry is meant to be used when isResponseFresh returns false. The algorithm is as follows: if last-modified and date are defined, freshness lifetime is coefficient*(date-lastModified), else freshness lifetime is defaultLifetime- Parameters:
entry- the cache entrynow- what time is it currently (When is right NOW)coefficient- Part of the heuristic for cache entry freshnessdefaultLifetime- How long can I assume a cache entry is default TTL- Returns:
trueif the response is fresh
-
getHeuristicFreshnessLifetime
public org.apache.hc.core5.util.TimeValue getHeuristicFreshnessLifetime(HttpCacheEntry entry, float coefficient, org.apache.hc.core5.util.TimeValue defaultLifetime) -
isRevalidatable
-
mustRevalidate
-
proxyRevalidate
-
mayReturnStaleWhileRevalidating
-
mayReturnStaleIfError
public boolean mayReturnStaleIfError(org.apache.hc.core5.http.HttpRequest request, HttpCacheEntry entry, Instant now) -
mayReturnStaleIfError
private boolean mayReturnStaleIfError(org.apache.hc.core5.http.MessageHeaders headers, String name, org.apache.hc.core5.util.TimeValue staleness) -
contentLengthHeaderMatchesActualLength
This matters for deciding whether the cache entry is valid to serve as a response. If these values do not match, we might have a partial response- Parameters:
entry- The cache entry we are currently working with- Returns:
- boolean indicating whether actual length matches Content-Length
-
getApparentAge
-
getAgeValue
-
getCorrectedReceivedAge
-
getResponseDelay
-
getCorrectedInitialAge
-
getResidentTime
-
getMaxAge
-
hasCacheControlDirective
-
getStaleness
-