Class CacheValidityPolicy


  • @Contract(threading=IMMUTABLE)
    class CacheValidityPolicy
    extends java.lang.Object
    Since:
    4.1
    • Constructor Detail

      • CacheValidityPolicy

        CacheValidityPolicy()
    • Method Detail

      • getCurrentAgeSecs

        public long getCurrentAgeSecs​(HttpCacheEntry entry,
                                      java.util.Date now)
      • getFreshnessLifetimeSecs

        public long getFreshnessLifetimeSecs​(HttpCacheEntry entry)
      • isResponseFresh

        public boolean isResponseFresh​(HttpCacheEntry entry,
                                       java.util.Date now)
      • isResponseHeuristicallyFresh

        public boolean isResponseHeuristicallyFresh​(HttpCacheEntry entry,
                                                    java.util.Date now,
                                                    float coefficient,
                                                    long defaultLifetime)
        Decides if this response is fresh enough based Last-Modified and Date, if available. This entry is meant to be used when isResponseFresh returns false. The algorithm is as follows: if last-modified and date are defined, freshness lifetime is coefficient*(date-lastModified), else freshness lifetime is defaultLifetime
        Parameters:
        entry - the cache entry
        now - what time is it currently (When is right NOW)
        coefficient - Part of the heuristic for cache entry freshness
        defaultLifetime - How long can I assume a cache entry is default TTL
        Returns:
        true if the response is fresh
      • getHeuristicFreshnessLifetimeSecs

        public long getHeuristicFreshnessLifetimeSecs​(HttpCacheEntry entry,
                                                      float coefficient,
                                                      long defaultLifetime)
      • isRevalidatable

        public boolean isRevalidatable​(HttpCacheEntry entry)
      • mustRevalidate

        public boolean mustRevalidate​(HttpCacheEntry entry)
      • proxyRevalidate

        public boolean proxyRevalidate​(HttpCacheEntry entry)
      • mayReturnStaleWhileRevalidating

        public boolean mayReturnStaleWhileRevalidating​(HttpCacheEntry entry,
                                                       java.util.Date now)
      • mayReturnStaleIfError

        public boolean mayReturnStaleIfError​(org.apache.http.HttpRequest request,
                                             HttpCacheEntry entry,
                                             java.util.Date now)
      • mayReturnStaleIfError

        private boolean mayReturnStaleIfError​(org.apache.http.Header[] headers,
                                              long stalenessSecs)
      • getLastModifiedValue

        protected java.util.Date getLastModifiedValue​(HttpCacheEntry entry)
      • getContentLengthValue

        protected long getContentLengthValue​(HttpCacheEntry entry)
      • hasContentLengthHeader

        protected boolean hasContentLengthHeader​(HttpCacheEntry entry)
      • contentLengthHeaderMatchesActualLength

        protected boolean contentLengthHeaderMatchesActualLength​(HttpCacheEntry entry)
        This matters for deciding whether the cache entry is valid to serve as a response. If these values do not match, we might have a partial response
        Parameters:
        entry - The cache entry we are currently working with
        Returns:
        boolean indicating whether actual length matches Content-Length
      • getApparentAgeSecs

        protected long getApparentAgeSecs​(HttpCacheEntry entry)
      • getCorrectedReceivedAgeSecs

        protected long getCorrectedReceivedAgeSecs​(HttpCacheEntry entry)
      • getResponseDelaySecs

        protected long getResponseDelaySecs​(HttpCacheEntry entry)
      • getCorrectedInitialAgeSecs

        protected long getCorrectedInitialAgeSecs​(HttpCacheEntry entry)
      • getResidentTimeSecs

        protected long getResidentTimeSecs​(HttpCacheEntry entry,
                                           java.util.Date now)
      • getExpirationDate

        protected java.util.Date getExpirationDate​(HttpCacheEntry entry)
      • hasCacheControlDirective

        public boolean hasCacheControlDirective​(HttpCacheEntry entry,
                                                java.lang.String directive)
      • getStalenessSecs

        public long getStalenessSecs​(HttpCacheEntry entry,
                                     java.util.Date now)