parent
10ab37b775
commit
dac57c57f6
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue