hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject httpcomponents-client git commit: Closes PR #78 Avoid fetching the cached entity twice on cache hit. [Forced Update!]
Date Mon, 29 May 2017 19:02:43 GMT
Repository: httpcomponents-client
Updated Branches:
  refs/heads/4.6.x f85117f29 -> dcf0c95b4 (forced update)


Closes PR #78
Avoid fetching the cached entity twice on cache hit.

(cherry picked from commit f59181e)


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/dcf0c95b
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/dcf0c95b
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/dcf0c95b

Branch: refs/heads/4.6.x
Commit: dcf0c95b423070040bd06efadea92ad9f430d287
Parents: f8e7d98
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:02:02 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/dcf0c95b/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/dcf0c95b/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/dcf0c95b/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();
+    }
+
 }


Mime
View raw message