Class CacheValidityPolicy

java.lang.Object
org.apache.hc.client5.http.impl.cache.CacheValidityPolicy

class CacheValidityPolicy extends Object
  • Field Details

    • LOG

      private static final org.slf4j.Logger LOG
    • shared

      private final boolean shared
    • useHeuristicCaching

      private final boolean useHeuristicCaching
    • heuristicCoefficient

      private final float heuristicCoefficient
    • heuristicDefaultLifetime

      private final org.apache.hc.core5.util.TimeValue heuristicDefaultLifetime
  • Constructor Details

    • CacheValidityPolicy

      CacheValidityPolicy(CacheConfig config)
      Constructs a CacheValidityPolicy with the provided CacheConfig. If the config is null, it will use default heuristic coefficient and default heuristic lifetime from CacheConfig.DEFAULT.
      Parameters:
      config - The CacheConfig to use for this CacheValidityPolicy. If null, default values are used.
    • CacheValidityPolicy

      CacheValidityPolicy()
      Default constructor for CacheValidityPolicy. Initializes the policy with default values.
  • Method Details

    • getCurrentAge

      public org.apache.hc.core5.util.TimeValue getCurrentAge(HttpCacheEntry entry, Instant now)
    • getFreshnessLifetime

      public org.apache.hc.core5.util.TimeValue getFreshnessLifetime(ResponseCacheControl responseCacheControl, HttpCacheEntry entry)
      Calculate the freshness lifetime of a response based on the provided cache control and cache entry.
      • If the cache is shared and the s-maxage response directive is present, use its value.
      • If the max-age response directive is present, use its value.
      • If the Expires response header field is present, use its value minus the value of the Date response header field.
      • Otherwise, a heuristic freshness lifetime might be applicable.
      Parameters:
      responseCacheControl - the cache control directives associated with the response.
      entry - the cache entry associated with the response.
      Returns:
      the calculated freshness lifetime as a TimeValue.
    • getHeuristicFreshnessLifetime

      org.apache.hc.core5.util.TimeValue getHeuristicFreshnessLifetime(HttpCacheEntry entry)
    • getApparentAge

      org.apache.hc.core5.util.TimeValue getApparentAge(HttpCacheEntry entry)
    • getAgeValue

      long getAgeValue(HttpCacheEntry entry)
      Extracts and processes the Age value from an HttpCacheEntry by tokenizing the Age header value. The Age header value is interpreted as a sequence of tokens, and the first token is parsed into a number representing the age in delta-seconds. If the first token cannot be parsed into a number, the Age value is considered as invalid and this method returns 0. If the first token represents a negative number or a number that exceeds Integer.MAX_VALUE, the Age value is set to MAX_AGE (in seconds). This method uses CacheSupport.parseTokens to robustly handle the Age header value.

      Note: If the HttpCacheEntry contains multiple Age headers, only the first one is considered.

      Parameters:
      entry - The HttpCacheEntry from which to extract the Age value.
      Returns:
      The Age value in delta-seconds, or MAX_AGE in seconds if the Age value exceeds Integer.MAX_VALUE or is negative. If the Age value is invalid (cannot be parsed into a number or contains non-numeric characters), this method returns 0.
    • getCorrectedAgeValue

      org.apache.hc.core5.util.TimeValue getCorrectedAgeValue(HttpCacheEntry entry)
    • getResponseDelay

      org.apache.hc.core5.util.TimeValue getResponseDelay(HttpCacheEntry entry)
    • getCorrectedInitialAge

      org.apache.hc.core5.util.TimeValue getCorrectedInitialAge(HttpCacheEntry entry)
    • getResidentTime

      org.apache.hc.core5.util.TimeValue getResidentTime(HttpCacheEntry entry, Instant now)