Skip to content

Commit 3a46ebc

Browse files
committed
HTTP cache protocol interceptors to use SimpleHttpRequest internally for cache operations; the use of self-contained request object should help simplify handling of requests with an enclosed entity such as QUERY
1 parent 7f316c0 commit 3a46ebc

12 files changed

Lines changed: 415 additions & 348 deletions

File tree

httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java

Lines changed: 180 additions & 165 deletions
Large diffs are not rendered by default.

httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpAsyncCache.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Set;
3737
import java.util.stream.Collectors;
3838

39+
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
3940
import org.apache.hc.client5.http.cache.HttpAsyncCacheStorage;
4041
import org.apache.hc.client5.http.cache.HttpCacheCASOperation;
4142
import org.apache.hc.client5.http.cache.HttpCacheEntry;
@@ -53,7 +54,6 @@
5354
import org.apache.hc.core5.concurrent.FutureCallback;
5455
import org.apache.hc.core5.http.HttpHeaders;
5556
import org.apache.hc.core5.http.HttpHost;
56-
import org.apache.hc.core5.http.HttpRequest;
5757
import org.apache.hc.core5.http.HttpResponse;
5858
import org.apache.hc.core5.http.HttpStatus;
5959
import org.apache.hc.core5.http.Method;
@@ -93,7 +93,7 @@ public BasicHttpAsyncCache(final ResourceFactory resourceFactory, final HttpAsyn
9393
}
9494

9595
@Override
96-
public Cancellable match(final HttpHost host, final HttpRequest request, final FutureCallback<CacheMatch> callback) {
96+
public Cancellable match(final HttpHost host, final SimpleHttpRequest request, final FutureCallback<CacheMatch> callback) {
9797
final String rootKey = cacheKeyGenerator.generateKey(host, request);
9898
if (LOG.isDebugEnabled()) {
9999
LOG.debug("Get cache entry: {}", rootKey);
@@ -384,7 +384,7 @@ public void completed(final Boolean result) {
384384
@Override
385385
public Cancellable store(
386386
final HttpHost host,
387-
final HttpRequest request,
387+
final SimpleHttpRequest request,
388388
final HttpResponse originResponse,
389389
final ByteArrayBuffer content,
390390
final Instant requestSent,
@@ -424,7 +424,7 @@ public Cancellable store(
424424
public Cancellable update(
425425
final CacheHit stale,
426426
final HttpHost host,
427-
final HttpRequest request,
427+
final SimpleHttpRequest request,
428428
final HttpResponse originResponse,
429429
final Instant requestSent,
430430
final Instant responseReceived,
@@ -447,7 +447,7 @@ public Cancellable update(
447447
public Cancellable storeFromNegotiated(
448448
final CacheHit negotiated,
449449
final HttpHost host,
450-
final HttpRequest request,
450+
final SimpleHttpRequest request,
451451
final HttpResponse originResponse,
452452
final Instant requestSent,
453453
final Instant responseReceived,
@@ -543,7 +543,7 @@ public void cancelled() {
543543

544544
@Override
545545
public Cancellable evictInvalidatedEntries(
546-
final HttpHost host, final HttpRequest request, final HttpResponse response, final FutureCallback<Boolean> callback) {
546+
final HttpHost host, final SimpleHttpRequest request, final HttpResponse response, final FutureCallback<Boolean> callback) {
547547
if (LOG.isDebugEnabled()) {
548548
LOG.debug("Flush cache entries invalidated by exchange: {}; {} {} -> {}",
549549
host, request.getMethod(), request.getRequestUri(), response.getCode());

httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpCache.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.List;
3535
import java.util.Set;
3636

37+
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
3738
import org.apache.hc.client5.http.cache.HttpCacheCASOperation;
3839
import org.apache.hc.client5.http.cache.HttpCacheEntry;
3940
import org.apache.hc.client5.http.cache.HttpCacheEntryFactory;
@@ -46,7 +47,6 @@
4647
import org.apache.hc.client5.http.validator.ValidatorType;
4748
import org.apache.hc.core5.http.HttpHeaders;
4849
import org.apache.hc.core5.http.HttpHost;
49-
import org.apache.hc.core5.http.HttpRequest;
5050
import org.apache.hc.core5.http.HttpResponse;
5151
import org.apache.hc.core5.http.HttpStatus;
5252
import org.apache.hc.core5.http.Method;
@@ -139,7 +139,7 @@ private void removeInternal(final String cacheKey) {
139139
}
140140

141141
@Override
142-
public CacheMatch match(final HttpHost host, final HttpRequest request) {
142+
public CacheMatch match(final HttpHost host, final SimpleHttpRequest request) {
143143
final String rootKey = cacheKeyGenerator.generateKey(host, request);
144144
if (LOG.isDebugEnabled()) {
145145
LOG.debug("Get cache root entry: {}", rootKey);
@@ -218,7 +218,7 @@ CacheHit store(final String rootKey, final String variantKey, final HttpCacheEnt
218218
@Override
219219
public CacheHit store(
220220
final HttpHost host,
221-
final HttpRequest request,
221+
final SimpleHttpRequest request,
222222
final HttpResponse originResponse,
223223
final ByteArrayBuffer content,
224224
final Instant requestSent,
@@ -256,7 +256,7 @@ public CacheHit store(
256256
public CacheHit update(
257257
final CacheHit stale,
258258
final HttpHost host,
259-
final HttpRequest request,
259+
final SimpleHttpRequest request,
260260
final HttpResponse originResponse,
261261
final Instant requestSent,
262262
final Instant responseReceived) {
@@ -278,7 +278,7 @@ public CacheHit update(
278278
public CacheHit storeFromNegotiated(
279279
final CacheHit negotiated,
280280
final HttpHost host,
281-
final HttpRequest request,
281+
final SimpleHttpRequest request,
282282
final HttpResponse originResponse,
283283
final Instant requestSent,
284284
final Instant responseReceived) {
@@ -339,7 +339,7 @@ private void evict(final String rootKey, final HttpResponse response) {
339339
}
340340

341341
@Override
342-
public void evictInvalidatedEntries(final HttpHost host, final HttpRequest request, final HttpResponse response) {
342+
public void evictInvalidatedEntries(final HttpHost host, final SimpleHttpRequest request, final HttpResponse response) {
343343
if (LOG.isDebugEnabled()) {
344344
LOG.debug("Evict cache entries invalidated by exchange: {}; {} {} -> {}",
345345
host, request.getMethod(), request.getRequestUri(), response.getCode());

0 commit comments

Comments
 (0)