arturobernalg commented on code in PR #449:
URL:
https://github.com/apache/httpcomponents-client/pull/449#discussion_r1199656573
##########
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachedResponseSuitabilityChecker.java:
##########
@@ -69,84 +70,51 @@ class CachedResponseSuitabilityChecker {
this(new CacheValidityPolicy(), config);
}
- private boolean isFreshEnough(final HttpCacheEntry entry, final
HttpRequest request, final Instant now) {
- if (validityStrategy.isResponseFresh(entry, now)) {
+ private boolean isFreshEnough(final RequestCacheControl
requestCacheControl,
+ final ResponseCacheControl
responseCacheControl, final HttpCacheEntry entry,
+ final Instant now) {
+ if (validityStrategy.isResponseFresh(responseCacheControl, entry,
now)) {
return true;
}
if (useHeuristicCaching &&
validityStrategy.isResponseHeuristicallyFresh(entry, now,
heuristicCoefficient, heuristicDefaultLifetime)) {
return true;
}
- if (originInsistsOnFreshness(entry)) {
+ if (originInsistsOnFreshness(responseCacheControl, entry)) {
return false;
}
- final long maxStale = getMaxStale(request);
- if (maxStale == -1) {
+ if (requestCacheControl.getMaxStale() == -1) {
return false;
}
- return (maxStale > validityStrategy.getStaleness(entry,
now).toSeconds());
+ return (requestCacheControl.getMaxStale() >
validityStrategy.getStaleness(responseCacheControl, entry, now).toSeconds());
}
- private boolean originInsistsOnFreshness(final HttpCacheEntry entry) {
- if (validityStrategy.mustRevalidate(entry)) {
+ private boolean originInsistsOnFreshness(final ResponseCacheControl
responseCacheControl, final HttpCacheEntry entry) {
+ if (responseCacheControl.isMustRevalidate()) {
return true;
}
if (!sharedCache) {
return false;
}
- return validityStrategy.proxyRevalidate(entry) ||
- validityStrategy.hasCacheControlDirective(entry, "s-maxage");
- }
-
- private long getMaxStale(final HttpRequest request) {
- // This is a header value, we leave as-is
- long maxStale = -1;
- final Iterator<HeaderElement> it = MessageSupport.iterate(request,
HeaderConstants.CACHE_CONTROL);
- while (it.hasNext()) {
- final HeaderElement elt = it.next();
- if (HeaderConstants.CACHE_CONTROL_MAX_STALE.equals(elt.getName()))
{
- if ((elt.getValue() == null ||
elt.getValue().trim().isEmpty()) && maxStale == -1) {
- maxStale = Long.MAX_VALUE;
- } else {
- try {
- long val = Long.parseLong(elt.getValue());
- if (val < 0) {
- val = 0;
- }
- if (maxStale == -1 || val < maxStale) {
- maxStale = val;
- }
- } catch (final NumberFormatException nfe) {
- // err on the side of preserving semantic transparency
- maxStale = 0;
- }
- }
- }
- }
- return maxStale;
+ final ResponseCacheControl cacheControl =
CacheControlHeaderParser.INSTANCE.parse(entry);
Review Comment:
I might be mistaken or perhaps missing something, but don't we already have
the ResponseCacheControl? It seems like we just need to pass it through the
'isFreshEnough' method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]