Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPCLIENT-2277: internal cache API and cache update redesign #483

Merged
merged 2 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,38 +173,24 @@ static String normalizeRequestUri(final HttpHost host, final HttpRequest request
/**
* Creates a new root {@link HttpCacheEntry} (parent of multiple variants).
*
* @param requestInstant Date/time when the request was made (Used for age calculations)
* @param responseInstant Date/time that the response came back (Used for age calculations)
* @param host Target host
* @param request Original client request (a deep copy of this object is made)
* @param latestVariant The most recently created variant entry
* @param variants describing cache entries that are variants of this parent entry; this
* maps a "variant key" (derived from the varying request headers) to a
* "cache key" (where in the cache storage the particular variant is
* located)
*/
public HttpCacheEntry createRoot(final Instant requestInstant,
final Instant responseInstant,
final HttpHost host,
final HttpRequest request,
final HttpResponse response,
public HttpCacheEntry createRoot(final HttpCacheEntry latestVariant,
final Collection<String> variants) {
Args.notNull(requestInstant, "Request instant");
Args.notNull(responseInstant, "Response instant");
Args.notNull(host, "Host");
Args.notNull(request, "Request");
Args.notNull(response, "Origin response");
final String requestUri = normalizeRequestUri(host, request);
final HeaderGroup requestHeaders = filterHopByHopHeaders(request);
final HeaderGroup responseHeaders = filterHopByHopHeaders(response);
ensureDate(responseHeaders, responseInstant);
Args.notNull(latestVariant, "Request");
Args.notNull(variants, "Variants");
return new HttpCacheEntry(
requestInstant,
responseInstant,
request.getMethod(),
requestUri,
requestHeaders,
response.getCode(),
responseHeaders,
latestVariant.getRequestInstant(),
latestVariant.getResponseInstant(),
latestVariant.getRequestMethod(),
latestVariant.getRequestURI(),
headers(latestVariant.requestHeaderIterator()),
latestVariant.getStatus(),
headers(latestVariant.headerIterator()),
null,
variants);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -938,8 +938,10 @@ void negotiateResponseFromVariants(

void updateVariantCacheEntry(final HttpResponse backendResponse, final Instant responseDate, final CacheHit match) {
recordCacheUpdate(scope.clientContext);
operation.setDependency(responseCache.update(
operation.setDependency(responseCache.storeFromNegotiated(
match,
target,
request,
backendResponse,
requestDate,
responseDate,
Expand All @@ -953,31 +955,7 @@ public void completed(final CacheHit hit) {
} else {
try {
final SimpleHttpResponse cacheResponse = responseGenerator.generateResponse(request, hit.entry);
operation.setDependency(responseCache.storeReusing(
hit,
target,
request,
backendResponse,
requestDate,
responseDate,
new FutureCallback<CacheHit>() {

@Override
public void completed(final CacheHit result) {
triggerResponse(cacheResponse, scope, asyncExecCallback);
}

@Override
public void failed(final Exception ex) {
asyncExecCallback.failed(ex);
}

@Override
public void cancelled() {
asyncExecCallback.failed(new InterruptedIOException());
}

}));
triggerResponse(cacheResponse, scope, asyncExecCallback);
} catch (final ResourceIOException ex) {
asyncExecCallback.failed(ex);
}
Expand Down
Loading