List of usage examples for org.apache.http.client.cache HeaderConstants CACHE_CONTROL_NO_STORE
String CACHE_CONTROL_NO_STORE
To view the source code for org.apache.http.client.cache HeaderConstants CACHE_CONTROL_NO_STORE.
Click Source Link
From source file:org.apache.http.impl.client.cache.CacheableRequestPolicy.java
/** * Determines if an HttpRequest can be served from the cache. * * @param request/*from w w w. ja va 2 s . com*/ * an HttpRequest * @return boolean Is it possible to serve this request from cache */ public boolean isServableFromCache(HttpRequest request) { String method = request.getRequestLine().getMethod(); ProtocolVersion pv = request.getRequestLine().getProtocolVersion(); if (HttpVersion.HTTP_1_1.compareToVersion(pv) != 0) { log.debug("Request was not serveable from cache"); return false; } if (!method.equals(HeaderConstants.GET_METHOD)) { log.debug("Request was not serveable from cache"); return false; } if (request.getHeaders(HeaderConstants.PRAGMA).length > 0) { log.debug("Request was not serveable from cache"); return false; } Header[] cacheControlHeaders = request.getHeaders(HeaderConstants.CACHE_CONTROL); for (Header cacheControl : cacheControlHeaders) { for (HeaderElement cacheControlElement : cacheControl.getElements()) { if (HeaderConstants.CACHE_CONTROL_NO_STORE.equalsIgnoreCase(cacheControlElement.getName())) { log.debug("Request was not serveable from Cache"); return false; } if (HeaderConstants.CACHE_CONTROL_NO_CACHE.equalsIgnoreCase(cacheControlElement.getName())) { log.debug("Request was not serveable from cache"); return false; } } } log.debug("Request was serveable from cache"); return true; }
From source file:org.apache.http.impl.client.cache.CachedResponseSuitabilityChecker.java
/** * Determine if I can utilize a {@link HttpCacheEntry} to respond to the given * {@link HttpRequest}/*from ww w. j a v a 2 s . c om*/ * * @param host * {@link HttpHost} * @param request * {@link HttpRequest} * @param entry * {@link HttpCacheEntry} * @return boolean yes/no answer */ public boolean canCachedResponseBeUsed(HttpHost host, HttpRequest request, HttpCacheEntry entry, Date now) { if (!isFreshEnough(entry, request, now)) { log.debug("Cache entry was not fresh enough"); return false; } if (!validityStrategy.contentLengthHeaderMatchesActualLength(entry)) { log.debug("Cache entry Content-Length and header information do not match"); return false; } if (hasUnsupportedConditionalHeaders(request)) { log.debug("Request contained conditional headers we don't handle"); return false; } if (isConditional(request) && !allConditionalsMatch(request, entry, now)) { return false; } for (Header ccHdr : request.getHeaders(HeaderConstants.CACHE_CONTROL)) { for (HeaderElement elt : ccHdr.getElements()) { if (HeaderConstants.CACHE_CONTROL_NO_CACHE.equals(elt.getName())) { log.debug("Response contained NO CACHE directive, cache was not suitable"); return false; } if (HeaderConstants.CACHE_CONTROL_NO_STORE.equals(elt.getName())) { log.debug("Response contained NO STORE directive, cache was not suitable"); return false; } if (HeaderConstants.CACHE_CONTROL_MAX_AGE.equals(elt.getName())) { try { int maxage = Integer.parseInt(elt.getValue()); if (validityStrategy.getCurrentAgeSecs(entry, now) > maxage) { log.debug("Response from cache was NOT suitable due to max age"); return false; } } catch (NumberFormatException ex) { // err conservatively log.debug("Response from cache was malformed: " + ex.getMessage()); return false; } } if (HeaderConstants.CACHE_CONTROL_MAX_STALE.equals(elt.getName())) { try { int maxstale = Integer.parseInt(elt.getValue()); if (validityStrategy.getFreshnessLifetimeSecs(entry) > maxstale) { log.debug("Response from cache was not suitable due to Max stale freshness"); return false; } } catch (NumberFormatException ex) { // err conservatively log.debug("Response from cache was malformed: " + ex.getMessage()); return false; } } if (HeaderConstants.CACHE_CONTROL_MIN_FRESH.equals(elt.getName())) { try { long minfresh = Long.parseLong(elt.getValue()); if (minfresh < 0L) return false; long age = validityStrategy.getCurrentAgeSecs(entry, now); long freshness = validityStrategy.getFreshnessLifetimeSecs(entry); if (freshness - age < minfresh) { log.debug("Response from cache was not suitable due to min fresh " + "freshness requirement"); return false; } } catch (NumberFormatException ex) { // err conservatively log.debug("Response from cache was malformed: " + ex.getMessage()); return false; } } } } log.debug("Response from cache was suitable"); return true; }
From source file:org.apache.http.impl.client.cache.ResponseCachingPolicy.java
protected boolean isExplicitlyNonCacheable(HttpResponse response) { Header[] cacheControlHeaders = response.getHeaders(HeaderConstants.CACHE_CONTROL); for (Header header : cacheControlHeaders) { for (HeaderElement elem : header.getElements()) { if (HeaderConstants.CACHE_CONTROL_NO_STORE.equals(elem.getName()) || HeaderConstants.CACHE_CONTROL_NO_CACHE.equals(elem.getName()) || (sharedCache && "private".equals(elem.getName()))) { return true; }/*from w ww. ja v a 2 s . c o m*/ } } return false; }