ok2c commented on code in PR #464: URL: https://github.com/apache/httpcomponents-client/pull/464#discussion_r1244845040
########## httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheHit.java: ########## @@ -0,0 +1,60 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ +package org.apache.hc.client5.http.impl.cache; + +import org.apache.hc.client5.http.cache.HttpCacheEntry; + +class CacheHit { + + final String rootKey; + final String variantKey; + final HttpCacheEntry entry; + + public CacheHit(final String rootKey, final String variantKey, final HttpCacheEntry entry) { Review Comment: @arturobernalg The class is immutable. It is also internal so I forwent getters and null checks for its instance variables. ########## httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java: ########## @@ -507,29 +522,26 @@ ClassicHttpResponse negotiateResponseFromVariants( } final String resultEtag = resultEtagHeader.getValue(); - final Variant matchingVariant = variants.get(resultEtag); - if (matchingVariant == null) { + final CacheHit match = variantMap.get(resultEtag); + if (match == null) { LOG.debug("304 response did not contain ETag matching one sent in If-None-Match"); return callBackend(target, request, scope, chain); } - final HttpCacheEntry variantEntry = matchingVariant.getEntry(); - - if (revalidationResponseIsTooOld(backendResponse, variantEntry) + if (revalidationResponseIsTooOld(backendResponse, match.entry) && (request.getEntity() == null || request.getEntity().isRepeatable())) { final ClassicHttpRequest unconditional = conditionalRequestBuilder.buildUnconditionalRequest(request); return callBackend(target, unconditional, scope, chain); } recordCacheUpdate(scope.clientContext); - final HttpCacheEntry responseEntry = responseCache.updateVariantEntry( - target, conditionalRequest, backendResponse, variantEntry, requestDate, responseDate); - if (shouldSendNotModifiedResponse(request, responseEntry)) { - return convert(responseGenerator.generateNotModifiedResponse(responseEntry), scope); + final CacheHit hit = responseCache.update(match, backendResponse, requestDate, responseDate); + if (shouldSendNotModifiedResponse(request, hit.entry)) { + return convert(responseGenerator.generateNotModifiedResponse(hit.entry), scope); } - final SimpleHttpResponse response = responseGenerator.generateResponse(request, responseEntry); - responseCache.reuseVariantEntryFor(target, request, backendResponse, responseEntry, requestDate, responseDate); + final SimpleHttpResponse response = responseGenerator.generateResponse(request, hit.entry); + responseCache.storeReusing(hit, target, request, backendResponse, requestDate, responseDate); Review Comment: @arturobernalg Done. -- 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]
