public final HttpResponse getResponse(HttpRequest request) { if (isCacheable(request)) { String keyString = createKey(request); HttpResponse cached = getResponseImpl(keyString); if (responseStillUsable(cached)) { return cached; } } return null; }
public final HttpResponse getResponse(HttpRequest request) { if (isCacheable(request)) { String keyString = createKey(request); HttpResponse cached = getResponseImpl(keyString); if (responseStillUsable(cached)) { return cached; } } return null; }
protected boolean isCacheable(HttpRequest request, HttpResponse response) { if (!isCacheable(request)) { return false; } if (request.getCacheTtl() != -1) { // Caching was forced. Ignore what the response wants. return true; } if (response.getHttpStatusCode() == HttpResponse.SC_NOT_MODIFIED) { // Shindig server will serve 304s. Do not cache 304s from the origin server. return false; } // If the HTTP response allows for it, we can cache. return !response.isStrictNoCache(); }
protected boolean isCacheable(HttpRequest request, HttpResponse response, boolean allowStrictNoCacheResponses) { if (!isCacheable(request)) { return false; } if (request.getCacheTtl() != -1) { // Caching was forced. Ignore what the response wants. return true; } if (response.getHttpStatusCode() == HttpResponse.SC_NOT_MODIFIED) { // Shindig server will serve 304s. Do not cache 304s from the origin server. return false; } // If we allow strict no-cache responses or the HTTP response allows for it, we can cache. return allowStrictNoCacheResponses || !response.isStrictNoCache(); }
protected boolean isCacheable(HttpRequest request, HttpResponse response) { if (!isCacheable(request)) { return false; } if (request.getCacheTtl() != -1) { // Caching was forced. Ignore what the response wants. return true; } if (response.getHttpStatusCode() == HttpResponse.SC_NOT_MODIFIED) { // Shindig server will serve 304s. Do not cache 304s from the origin server. return false; } // If the HTTP response allows for it, we can cache. return !response.isStrictNoCache(); }
public HttpResponse getResponse(HttpRequest request) { if (isCacheable(request)) { String keyString = createKey(request); HttpResponse cached = getResponseImpl(keyString); if (responseStillUsable(cached) && (!cached.isStrictNoCache() || refetchStrictNoCacheAfterMs >= 0)) { return cached; } } return null; }
public boolean addResponse(HttpRequest request, HttpResponse response) { if (isCacheable(request, response)) { // Both are cacheable. Check for forced cache TTL overrides. HttpResponseBuilder responseBuilder = new HttpResponseBuilder(response); int forcedTtl = request.getCacheTtl(); if (forcedTtl != -1) { responseBuilder.setCacheTtl(forcedTtl); } response = responseBuilder.create(); String keyString = createKey(request); addResponseImpl(keyString, response); return true; } return false; }
public boolean addResponse(HttpRequest request, HttpResponse response) { if (isCacheable(request, response)) { // Both are cacheable. Check for forced cache TTL overrides. HttpResponseBuilder responseBuilder = new HttpResponseBuilder(response); int forcedTtl = request.getCacheTtl(); if (forcedTtl != -1) { responseBuilder.setCacheTtl(forcedTtl); } response = responseBuilder.create(); String keyString = createKey(request); addResponseImpl(keyString, response); return true; } return false; }
public HttpResponse addResponse(HttpRequest request, HttpResponse response) { HttpResponseBuilder responseBuilder; boolean storeStrictNoCacheResources = (refetchStrictNoCacheAfterMs >= 0); if (isCacheable(request, response, storeStrictNoCacheResources)) { if (storeStrictNoCacheResources && response.isStrictNoCache()) { responseBuilder = buildStrictNoCacheHttpResponse(response); } else { responseBuilder = new HttpResponseBuilder(response); } } else { return null; } int forcedTtl = request.getCacheTtl(); if (forcedTtl != -1 && !response.isError()) { responseBuilder.setCacheTtl(forcedTtl); } response = responseBuilder.create(); String keyString = createKey(request); addResponseImpl(keyString, response); return response; // cached and possibly modified }