Class CacheValidityPolicy
- java.lang.Object
-
- org.apache.hc.client5.http.impl.cache.CacheValidityPolicy
-
- Direct Known Subclasses:
HttpByteArrayCacheEntrySerializer.NoAgeCacheValidityPolicy
class CacheValidityPolicy extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static org.apache.hc.core5.util.TimeValue
MAX_AGE
-
Constructor Summary
Constructors Constructor Description CacheValidityPolicy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
contentLengthHeaderMatchesActualLength(HttpCacheEntry entry)
This matters for deciding whether the cache entry is valid to serve as a response.protected long
getAgeValue(HttpCacheEntry entry)
protected org.apache.hc.core5.util.TimeValue
getApparentAge(HttpCacheEntry entry)
protected org.apache.hc.core5.util.TimeValue
getCorrectedInitialAge(HttpCacheEntry entry)
protected org.apache.hc.core5.util.TimeValue
getCorrectedReceivedAge(HttpCacheEntry entry)
org.apache.hc.core5.util.TimeValue
getCurrentAge(HttpCacheEntry entry, java.time.Instant now)
org.apache.hc.core5.util.TimeValue
getFreshnessLifetime(HttpCacheEntry entry)
org.apache.hc.core5.util.TimeValue
getHeuristicFreshnessLifetime(HttpCacheEntry entry, float coefficient, org.apache.hc.core5.util.TimeValue defaultLifetime)
protected long
getMaxAge(HttpCacheEntry entry)
protected org.apache.hc.core5.util.TimeValue
getResidentTime(HttpCacheEntry entry, java.time.Instant now)
protected org.apache.hc.core5.util.TimeValue
getResponseDelay(HttpCacheEntry entry)
org.apache.hc.core5.util.TimeValue
getStaleness(HttpCacheEntry entry, java.time.Instant now)
boolean
hasCacheControlDirective(HttpCacheEntry entry, java.lang.String directive)
boolean
isResponseFresh(HttpCacheEntry entry, java.time.Instant now)
boolean
isResponseHeuristicallyFresh(HttpCacheEntry entry, java.time.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.boolean
isRevalidatable(HttpCacheEntry entry)
boolean
mayReturnStaleIfError(org.apache.hc.core5.http.HttpRequest request, HttpCacheEntry entry, java.time.Instant now)
private boolean
mayReturnStaleIfError(org.apache.hc.core5.http.MessageHeaders headers, java.lang.String name, org.apache.hc.core5.util.TimeValue staleness)
boolean
mayReturnStaleWhileRevalidating(HttpCacheEntry entry, java.time.Instant now)
boolean
mustRevalidate(HttpCacheEntry entry)
boolean
proxyRevalidate(HttpCacheEntry entry)
-
-
-
Method Detail
-
getCurrentAge
public org.apache.hc.core5.util.TimeValue getCurrentAge(HttpCacheEntry entry, java.time.Instant now)
-
getFreshnessLifetime
public org.apache.hc.core5.util.TimeValue getFreshnessLifetime(HttpCacheEntry entry)
-
isResponseFresh
public boolean isResponseFresh(HttpCacheEntry entry, java.time.Instant now)
-
isResponseHeuristicallyFresh
public boolean isResponseHeuristicallyFresh(HttpCacheEntry entry, java.time.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:
true
if 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
public boolean isRevalidatable(HttpCacheEntry entry)
-
mustRevalidate
public boolean mustRevalidate(HttpCacheEntry entry)
-
proxyRevalidate
public boolean proxyRevalidate(HttpCacheEntry entry)
-
mayReturnStaleWhileRevalidating
public boolean mayReturnStaleWhileRevalidating(HttpCacheEntry entry, java.time.Instant now)
-
mayReturnStaleIfError
public boolean mayReturnStaleIfError(org.apache.hc.core5.http.HttpRequest request, HttpCacheEntry entry, java.time.Instant now)
-
mayReturnStaleIfError
private boolean mayReturnStaleIfError(org.apache.hc.core5.http.MessageHeaders headers, java.lang.String name, org.apache.hc.core5.util.TimeValue staleness)
-
contentLengthHeaderMatchesActualLength
protected boolean contentLengthHeaderMatchesActualLength(HttpCacheEntry entry)
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
protected org.apache.hc.core5.util.TimeValue getApparentAge(HttpCacheEntry entry)
-
getAgeValue
protected long getAgeValue(HttpCacheEntry entry)
-
getCorrectedReceivedAge
protected org.apache.hc.core5.util.TimeValue getCorrectedReceivedAge(HttpCacheEntry entry)
-
getResponseDelay
protected org.apache.hc.core5.util.TimeValue getResponseDelay(HttpCacheEntry entry)
-
getCorrectedInitialAge
protected org.apache.hc.core5.util.TimeValue getCorrectedInitialAge(HttpCacheEntry entry)
-
getResidentTime
protected org.apache.hc.core5.util.TimeValue getResidentTime(HttpCacheEntry entry, java.time.Instant now)
-
getMaxAge
protected long getMaxAge(HttpCacheEntry entry)
-
hasCacheControlDirective
public boolean hasCacheControlDirective(HttpCacheEntry entry, java.lang.String directive)
-
getStaleness
public org.apache.hc.core5.util.TimeValue getStaleness(HttpCacheEntry entry, java.time.Instant now)
-
-