[prev in list] [next in list] [prev in thread] [next in thread]
List: httpcomponents-commits
Subject: [2/2] httpcomponents-client git commit: Closes PR #77 Avoid fetching the cached entity twice on cach
From: olegk () apache ! org
Date: 2017-05-29 19:17:07
Message-ID: 425be7a0bfed4f34ad03862c6d836142 () git ! apache ! org
[Download RAW message or body]
Closes PR #77
Avoid fetching the cached entity twice on cache hit.
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/dac57c57
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/dac57c57
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/dac57c57
Branch: refs/heads/4.5.x
Commit: dac57c57f655efb50c6bdc6bb9ba0b53e5a674a6
Parents: 10ab37b
Author: Leandro Nunes <a-lnunes@hotels.com>
Authored: Thu May 18 15:55:42 2017 +0100
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Mon May 29 21:14:36 2017 +0200
----------------------------------------------------------------------
.../http/impl/client/cache/CachingExec.java | 3 +--
.../http/impl/client/cache/TestCachingExec.java | 20 ++++++++++++++++++++
.../impl/client/cache/TestCachingExecChain.java | 5 +++++
3 files changed, 26 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/dac57c57/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java
----------------------------------------------------------------------
diff --git a/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java \
b/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java \
index 67f5748..33bdbf1 100644
--- a/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java
+++ b/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java
@@ -263,10 +263,9 @@ public class CachingExec implements ClientExecChain {
requestCompliance.makeRequestCompliant(request);
request.addHeader("Via",via);
- flushEntriesInvalidatedByRequest(context.getTargetHost(), request);
-
if (!cacheableRequestPolicy.isServableFromCache(request)) {
log.debug("Request is not servable from cache");
+ flushEntriesInvalidatedByRequest(context.getTargetHost(), request);
return callBackend(route, request, context, execAware);
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/dac57c57/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java
----------------------------------------------------------------------
diff --git a/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java \
b/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java
index 553163a..5524f1e 100644
--- a/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java
+++ b/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java
@@ -402,6 +402,26 @@ public class TestCachingExec extends TestCachingExecChain {
verifyMocks();
}
+ @Test
+ public void testDoesNotFlushCachesOnCacheHit() throws Exception {
+ requestPolicyAllowsCaching(true);
+ requestIsFatallyNonCompliant(null);
+
+ getCacheEntryReturns(mockCacheEntry);
+ doesNotFlushCache();
+ cacheEntrySuitable(true);
+ cacheEntryValidatable(true);
+
+ expect(mockResponseGenerator.generateResponse(isA(HttpRequestWrapper.class), \
isA(HttpCacheEntry.class))) + .andReturn(mockBackendResponse);
+
+ replayMocks();
+ final HttpResponse result = impl.execute(route, request, context);
+ verifyMocks();
+
+ Assert.assertSame(mockBackendResponse, result);
+ }
+
private IExpectationSetters<CloseableHttpResponse> \
implExpectsAnyRequestAndReturn( final CloseableHttpResponse response) throws \
Exception { final CloseableHttpResponse resp = impl.callBackend(
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/dac57c57/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExecChain.java
----------------------------------------------------------------------
diff --git a/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExecChain.java \
b/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExecChain.java
index f2ddc67..b71caf9 100644
--- a/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExecChain.java
+++ b/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExecChain.java
@@ -1777,4 +1777,9 @@ public abstract class TestCachingExecChain {
.andReturn(mockCachedResponse);
}
+ protected void doesNotFlushCache() throws IOException {
+ mockCache.flushInvalidatedCacheEntriesFor(isA(HttpHost.class), \
isA(HttpRequest.class)); + EasyMock.expectLastCall().andThrow(new \
AssertionError("flushInvalidatedCacheEntriesFor should not have been \
called")).anyTimes(); + }
+
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic