/** * Cache the HttpResponse object before being returned to caller. * The default implementation also invalidate the response object by marking it as valid so the * next request can detect if it has been invalidated. * Override this if you need to add additional processing to cache the response. * * @param request * @param fetchedResponse * @return HttpResponse object that has been updated with some metadata tags. */ protected HttpResponse cacheFetchedResponse(HttpRequest request, HttpResponse fetchedResponse) { if (!request.getIgnoreCache()) { // Mark the response with invalidation information prior to caching if (fetchedResponse.getCacheTtl() > 0) { fetchedResponse = invalidationService.markResponse(request, fetchedResponse); } HttpResponse cached = httpCache.addResponse(request, fetchedResponse); if (cached != null) { fetchedResponse = cached; // possibly modified response. } } return fetchedResponse; }
@Test public void testFetchWithInvalidationEnabled() throws Exception { cache.addResponse(new HttpRequest(URI), CACHEABLE); assertEquals(CACHEABLE, requestPipeline.execute(new HttpRequest(URI))); }
@Test public void testFetchWithInvalidationEnabled() throws Exception { cache.addResponse(new HttpRequest(URI), CACHEABLE); assertEquals(CACHEABLE, requestPipeline.execute(new HttpRequest(URI))); }
@Test public void testFetchWithInvalidationEnabled() throws Exception { cache.addResponse(new HttpRequest(URI), CACHEABLE); assertEquals(CACHEABLE, requestPipeline.execute(new HttpRequest(URI))); }
@Test public void testInvalidateUrl() throws Exception { cache.addResponse(new HttpRequest(URI), CACHEABLE); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); service.invalidateApplicationResources( ImmutableSet.of(URI), appxToken); assertEquals(0, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); }
@Test public void testInvalidateUrl() throws Exception { cache.addResponse(new HttpRequest(URI), CACHEABLE); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); service.invalidateApplicationResources( ImmutableSet.of(URI), appxToken); assertEquals(0, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); }
@Test public void testFetchInvalidatedContent() throws Exception { // Prime the cache cache.addResponse(new HttpRequest(URI), CACHEABLE); // Invalidate the entry service.invalidateApplicationResources( ImmutableSet.of(URI), appxToken); fetcher.response = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT1"). create(); assertEquals(requestPipeline.execute(new HttpRequest(URI)), fetcher.response); }
@Test public void testFetchInvalidatedContent() throws Exception { // Prime the cache cache.addResponse(new HttpRequest(URI), CACHEABLE); // Invalidate the entry service.invalidateApplicationResources( ImmutableSet.of(URI), appxToken); fetcher.response = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT1"). create(); assertEquals(requestPipeline.execute(new HttpRequest(URI)), fetcher.response); }
@Test public void testInvalidateUrl() throws Exception { cache.addResponse(new HttpRequest(URI), CACHEABLE); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); service.invalidateApplicationResources( ImmutableSet.of(URI), appxToken); assertEquals(0, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); }
@Test public void testFetchInvalidatedContent() throws Exception { // Prime the cache cache.addResponse(new HttpRequest(URI), CACHEABLE); // Invalidate the entry service.invalidateApplicationResources( ImmutableSet.of(URI), appxToken); fetcher.response = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT1"). create(); assertEquals(requestPipeline.execute(new HttpRequest(URI)), fetcher.response); }
HttpRequest proxyRequest = createPipelinedProxyRequest(gadget, request); response = requestPipeline.execute(proxyRequest); httpCache.addResponse(request, response);
HttpRequest proxyRequest = createPipelinedProxyRequest(gadget, request); response = requestPipeline.execute(proxyRequest); httpCache.addResponse(request, response);
HttpRequest proxyRequest = createPipelinedProxyRequest(gadget, request); response = requestPipeline.execute(proxyRequest); httpCache.addResponse(request, response);
fetchedResponse = invalidationService.markResponse(request, fetchedResponse); httpCache.addResponse(request, fetchedResponse);
fetchedResponse = invalidationService.markResponse(request, fetchedResponse); httpCache.addResponse(request, fetchedResponse);