@Override public boolean getIgnoreCache() { return request.getIgnoreCache(); }
@Override public boolean getIgnoreCache() { return request.getIgnoreCache(); }
@Override public boolean getIgnoreCache() { return request.getIgnoreCache(); }
@Override public boolean getIgnoreCache() { return request.getIgnoreCache(); }
/** * Check the HttpRequest object has already allow caching and if do try to get it from cache. * Override this if you want to add additional logic to get response for the request from cache. * * @param request * @return HttpResponse object which either the cached response or null */ protected HttpResponse checkCachedResponse(HttpRequest request) { HttpResponse cachedResponse; if (!request.getIgnoreCache()) { cachedResponse = httpCache.getResponse(request); } else { cachedResponse = null; } return cachedResponse; }
protected boolean isCacheable(HttpRequest request) { if (request.getIgnoreCache()) { return false; } return ("GET".equals(request.getMethod()) || "GET".equals(request.getHeader("X-Method-Override"))); }
protected boolean isCacheable(HttpRequest request) { if (request.getIgnoreCache()) { return false; } return ("GET".equals(request.getMethod()) || "GET".equals(request.getHeader("X-Method-Override"))); }
protected boolean isCacheable(HttpRequest request) { if (request.getIgnoreCache()) { return false; } return ("GET".equals(request.getMethod()) || "GET".equals(request.getHeader("X-Method-Override"))); }
public Config get(HttpRequest request) { GadgetSpec spec; final Uri gadgetUrl = request.getGadget(); final boolean isIgnoreCache = request.getIgnoreCache(); if (gadgetUrl != null) { try { GadgetContext context = new GadgetContext() { @Override public Uri getUrl() { return gadgetUrl; } @Override public boolean getIgnoreCache() { return isIgnoreCache; } }; spec = specFactory.getGadgetSpec(context); if (spec != null) { return get(spec); } } catch (GadgetException ge) { // Falls through to default. } } return defaultConfig.get(); }
/** * 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; }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof HttpRequest)) { return false; } HttpRequest req = (HttpRequest)obj; return super.equals(obj) && req.getCacheTtl() == getCacheTtl() && req.getIgnoreCache() == getIgnoreCache(); }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof HttpRequest)) { return false; } HttpRequest req = (HttpRequest)obj; return super.equals(obj) && req.getCacheTtl() == getCacheTtl() && req.getIgnoreCache() == getIgnoreCache(); }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof HttpRequest)) { return false; } HttpRequest req = (HttpRequest)obj; return super.equals(obj) && req.getCacheTtl() == getCacheTtl() && req.getIgnoreCache() == getIgnoreCache(); }
@Test public void normalPreloads() throws Exception { String xml = "<Module><ModulePrefs title=''>" + " <Preload href='" + PRELOAD_HREF + "'/>" + "</ModulePrefs><Content/></Module>"; GadgetSpec spec = new GadgetSpec(GADGET_URL, xml); Preloader preloader = new HttpPreloader(requestPipeline); Gadget gadget = new Gadget() .setContext(context) .setSpec(spec) .setCurrentView(spec.getView(GadgetSpec.DEFAULT_VIEW)); Collection<Callable<PreloadedData>> preloaded = preloader.createPreloadTasks(gadget); assertEquals(1, preloaded.size()); PreloadedData data = preloaded.iterator().next().call(); checkRequest(plainFetcher.requests.get(0)); assertFalse("request should not ignore cache", plainFetcher.requests.get(0).getIgnoreCache()); checkResults(data.toJson().iterator().next()); }
@Test public void normalPreloads() throws Exception { String xml = "<Module><ModulePrefs title=''>" + " <Preload href='" + PRELOAD_HREF + "'/>" + "</ModulePrefs><Content/></Module>"; GadgetSpec spec = new GadgetSpec(GADGET_URL, xml); Preloader preloader = new HttpPreloader(requestPipeline); Gadget gadget = new Gadget() .setContext(context) .setSpec(spec) .setCurrentView(spec.getView(GadgetSpec.DEFAULT_VIEW)); Collection<Callable<PreloadedData>> preloaded = preloader.createPreloadTasks(gadget); assertEquals(1, preloaded.size()); PreloadedData data = preloaded.iterator().next().call(); checkRequest(plainFetcher.requests.get(0)); assertFalse("request should not ignore cache", plainFetcher.requests.get(0).getIgnoreCache()); checkResults(data.toJson().iterator().next()); }
@Test public void normalPreloads() throws Exception { String xml = "<Module><ModulePrefs title=''>" + " <Preload href='" + PRELOAD_HREF + "'/>" + "</ModulePrefs><Content/></Module>"; GadgetSpec spec = new GadgetSpec(GADGET_URL, xml); Preloader preloader = new HttpPreloader(requestPipeline); Gadget gadget = new Gadget() .setContext(context) .setSpec(spec) .setCurrentView(spec.getView(GadgetSpec.DEFAULT_VIEW)); Collection<Callable<PreloadedData>> preloaded = preloader.createPreloadTasks(gadget); assertEquals(1, preloaded.size()); PreloadedData data = preloaded.iterator().next().call(); checkRequest(plainFetcher.requests.get(0)); assertFalse("request should not ignore cache", plainFetcher.requests.get(0).getIgnoreCache()); checkResults(data.toJson().iterator().next()); }
@Test public void ignoreCachePreloads() throws Exception { String xml = "<Module><ModulePrefs title=''>" + " <Preload href='" + PRELOAD_HREF + "' authz='signed' sign_viewer='false'/>" + "</ModulePrefs><Content/></Module>"; GadgetSpec spec = new GadgetSpec(GADGET_URL, xml); Preloader preloader = new HttpPreloader(requestPipeline); ignoreCache = true; Gadget gadget = new Gadget() .setContext(context) .setSpec(spec) .setCurrentView(spec.getView(GadgetSpec.DEFAULT_VIEW)); Collection<Callable<PreloadedData>> preloaded = preloader.createPreloadTasks(gadget); assertEquals(1, preloaded.size()); preloaded.iterator().next().call(); HttpRequest request = oauthFetcher.requests.get(0); assertTrue("request should ignore cache", request.getIgnoreCache()); checkRequest(request); }
@Test public void ignoreCachePreloads() throws Exception { String xml = "<Module><ModulePrefs title=''>" + " <Preload href='" + PRELOAD_HREF + "' authz='signed' sign_viewer='false'/>" + "</ModulePrefs><Content/></Module>"; GadgetSpec spec = new GadgetSpec(GADGET_URL, xml); Preloader preloader = new HttpPreloader(requestPipeline); ignoreCache = true; Gadget gadget = new Gadget() .setContext(context) .setSpec(spec) .setCurrentView(spec.getView(GadgetSpec.DEFAULT_VIEW)); Collection<Callable<PreloadedData>> preloaded = preloader.createPreloadTasks(gadget); assertEquals(1, preloaded.size()); preloaded.iterator().next().call(); HttpRequest request = oauthFetcher.requests.get(0); assertTrue("request should ignore cache", request.getIgnoreCache()); checkRequest(request); }
@Test public void ignoreCachePreloads() throws Exception { String xml = "<Module><ModulePrefs title=''>" + " <Preload href='" + PRELOAD_HREF + "' authz='signed' sign_viewer='false'/>" + "</ModulePrefs><Content/></Module>"; GadgetSpec spec = new GadgetSpec(GADGET_URL, xml); Preloader preloader = new HttpPreloader(requestPipeline); ignoreCache = true; Gadget gadget = new Gadget() .setContext(context) .setSpec(spec) .setCurrentView(spec.getView(GadgetSpec.DEFAULT_VIEW)); Collection<Callable<PreloadedData>> preloaded = preloader.createPreloadTasks(gadget); assertEquals(1, preloaded.size()); preloaded.iterator().next().call(); HttpRequest request = oauthFetcher.requests.get(0); assertTrue("request should ignore cache", request.getIgnoreCache()); checkRequest(request); }
@Test public void testTemplateRequestAnonymousSecurityToken() throws GadgetException { CapturingPipeline pipeline = new CapturingPipeline(); TemplateLibraryFactory factory = new TemplateLibraryFactory( pipeline, null ); GadgetContext context = new GadgetContext() { @Override public Uri getUrl() { return SPEC_URL; } @Override public String getContainer() { return "default"; } @Override public boolean getDebug() { return false; } @Override public boolean getIgnoreCache() { return true; } }; factory.loadTemplateLibrary(context, TEMPLATE_URL); assertNotNull( pipeline.request ); SecurityToken st = pipeline.request.getSecurityToken(); assertNotNull( st ); assertTrue( st.isAnonymous() ); assertEquals( SPEC_URL.toString(), st.getAppUrl() ); assertTrue(pipeline.request.getIgnoreCache()); }