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: Avoid fetching the cached entity twice on cache hit. [Forced Update!]
Date Wed, 24 May 2017 18:43:33 GMT
Repository: httpcomponents-client
Updated Branches:
  refs/heads/master ae2535ca3 -> 45b23c7e0 (forced update)


Avoid fetching the cached entity twice on cache hit.

Closes PR #79
https://github.com/apache/httpcomponents-client/pull/79


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

Branch: refs/heads/master
Commit: 45b23c7e0a1dcb4bc07a9454ecfbf38d2f364f2b
Parents: e07fd9a
Author: Leandro Nunes <a-lnunes@hotels.com>
Authored: Fri May 19 12:28:20 2017 +0100
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Wed May 24 20:42:57 2017 +0200

----------------------------------------------------------------------
 .../hc/client5/http/impl/cache/CachingExec.java |  3 +--
 .../http/impl/cache/TestCachingExec.java        | 20 ++++++++++++++++++++
 .../http/impl/cache/TestCachingExecChain.java   |  5 +++++
 3 files changed, 26 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/45b23c7e/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
index 81b80f5..0507d85 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
@@ -246,10 +246,9 @@ public class CachingExec implements ExecChainHandler {
         requestCompliance.makeRequestCompliant(request);
         request.addHeader("Via",via);
 
-        flushEntriesInvalidatedByRequest(target, request);
-
         if (!cacheableRequestPolicy.isServableFromCache(request)) {
             log.debug("Request is not servable from cache");
+            flushEntriesInvalidatedByRequest(target, request);
             return callBackend(target, request, scope, chain);
         }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/45b23c7e/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java
b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java
index 727b338..281f859 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java
@@ -386,6 +386,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(HttpRequest.class), isA(HttpCacheEntry.class)))
+                .andReturn(mockBackendResponse);
+
+        replayMocks();
+        final HttpResponse result = impl.execute(request, scope, mockExecChain);
+        verifyMocks();
+
+        Assert.assertSame(mockBackendResponse, result);
+    }
+
     private IExpectationSetters<ClassicHttpResponse> implExpectsAnyRequestAndReturn(
             final ClassicHttpResponse response) throws Exception {
         final ClassicHttpResponse resp = impl.callBackend(

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/45b23c7e/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
index 7a848cd..00d3747 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
@@ -1673,4 +1673,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