Class HttpCacheEntry

java.lang.Object
org.apache.hc.client5.http.cache.HttpCacheEntry
All Implemented Interfaces:
Serializable, org.apache.hc.core5.http.MessageHeaders

@Contract(threading=IMMUTABLE) public class HttpCacheEntry extends Object implements org.apache.hc.core5.http.MessageHeaders, Serializable
Structure used to store an HttpResponse in a cache. Some entries can optionally depend on system resources that may require explicit deallocation. In such a case getResource() should return a non null instance of Resource that must be deallocated by calling Resource.dispose() method when no longer used.
Since:
4.1
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • requestDate

      private final Instant requestDate
    • responseDate

      private final Instant responseDate
    • method

      private final String method
    • requestURI

      private final String requestURI
    • requestHeaders

      private final org.apache.hc.core5.http.message.HeaderGroup requestHeaders
    • status

      private final int status
    • responseHeaders

      private final org.apache.hc.core5.http.message.HeaderGroup responseHeaders
    • resource

      private final Resource resource
    • variants

      private final Set<String> variants
    • dateRef

      private final AtomicReference<Instant> dateRef
    • expiresRef

      private final AtomicReference<Instant> expiresRef
    • lastModifiedRef

      private final AtomicReference<Instant> lastModifiedRef
    • eTagRef

      private final AtomicReference<ETag> eTagRef
    • NON_VALUE

      private static final Instant NON_VALUE
  • Constructor Details

    • HttpCacheEntry

      @Internal public HttpCacheEntry(Instant requestDate, Instant responseDate, String method, String requestURI, org.apache.hc.core5.http.message.HeaderGroup requestHeaders, int status, org.apache.hc.core5.http.message.HeaderGroup responseHeaders, Resource resource, Collection<String> variants)
      Internal constructor that makes no validation of the input parameters and makes no copies of the original client request and the origin response.
    • HttpCacheEntry

      @Deprecated public HttpCacheEntry(Date requestDate, Date responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource, Map<String,String> variantMap)
      Deprecated.
      Create a new HttpCacheEntry with variants.
      Parameters:
      requestDate - Date/time when the request was made (Used for age calculations)
      responseDate - Date/time that the response came back (Used for age calculations)
      status - HTTP status from origin response
      responseHeaders - Header[] from original HTTP Response
      resource - representing origin response body
      variantMap - describing cache entries that are variants of this parent entry; this maps a "variant key" (derived from the varying request headers) to a "cache key" (where in the cache storage the particular variant is located)
    • HttpCacheEntry

      @Deprecated public HttpCacheEntry(Instant requestDate, Instant responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource, Map<String,String> variantMap)
      Deprecated.
      Create a new HttpCacheEntry with variants.
      Parameters:
      requestDate - Date/time when the request was made (Used for age calculations)
      responseDate - Date/time that the response came back (Used for age calculations)
      status - HTTP status from origin response
      responseHeaders - Header[] from original HTTP Response
      resource - representing origin response body
      variantMap - describing cache entries that are variants of this parent entry; this maps a "variant key" (derived from the varying request headers) to a "cache key" (where in the cache storage the particular variant is located)
    • HttpCacheEntry

      @Deprecated public HttpCacheEntry(Date requestDate, Date responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource)
      Deprecated.
      Create a new HttpCacheEntry.
      Parameters:
      requestDate - Date/time when the request was made (Used for age calculations)
      responseDate - Date/time that the response came back (Used for age calculations)
      status - HTTP status from origin response
      responseHeaders - Header[] from original HTTP Response
      resource - representing origin response body
    • HttpCacheEntry

      @Deprecated public HttpCacheEntry(Instant requestDate, Instant responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource)
      Deprecated.
      Create a new HttpCacheEntry.
      Parameters:
      requestDate - Date/time when the request was made (Used for age calculations)
      responseDate - Date/time that the response came back (Used for age calculations)
      status - HTTP status from origin response
      responseHeaders - Header[] from original HTTP Response
      resource - representing origin response body
  • Method Details

    • getStatus

      public int getStatus()
      Returns the status from the origin HttpResponse.
    • getRequestDate

      @Deprecated public Date getRequestDate()
      Deprecated.
      Returns the time the associated origin request was initiated by the caching module.
      Returns:
      Date
    • getRequestInstant

      public Instant getRequestInstant()
      Returns the time the associated origin request was initiated by the caching module.
      Returns:
      Instant
      Since:
      5.2
    • getResponseDate

      @Deprecated public Date getResponseDate()
      Deprecated.
      Returns the time the origin response was received by the caching module.
      Returns:
      Date
    • getResponseInstant

      public Instant getResponseInstant()
      Returns the time the origin response was received by the caching module.
      Returns:
      Instant
      Since:
      5.2
    • getHeaders

      public org.apache.hc.core5.http.Header[] getHeaders()
      Returns all the headers that were on the origin response.
      Specified by:
      getHeaders in interface org.apache.hc.core5.http.MessageHeaders
    • getFirstHeader

      public org.apache.hc.core5.http.Header getFirstHeader(String name)
      Returns the first header from the origin response with the given name.
      Specified by:
      getFirstHeader in interface org.apache.hc.core5.http.MessageHeaders
    • getLastHeader

      public org.apache.hc.core5.http.Header getLastHeader(String name)
      Specified by:
      getLastHeader in interface org.apache.hc.core5.http.MessageHeaders
      Since:
      5.0
    • getHeaders

      public org.apache.hc.core5.http.Header[] getHeaders(String name)
      Gets all the headers with the given name that were on the origin response.
      Specified by:
      getHeaders in interface org.apache.hc.core5.http.MessageHeaders
    • containsHeader

      public boolean containsHeader(String name)
      Specified by:
      containsHeader in interface org.apache.hc.core5.http.MessageHeaders
      Since:
      5.0
    • countHeaders

      public int countHeaders(String name)
      Specified by:
      countHeaders in interface org.apache.hc.core5.http.MessageHeaders
      Since:
      5.0
    • getHeader

      public org.apache.hc.core5.http.Header getHeader(String name) throws org.apache.hc.core5.http.ProtocolException
      Specified by:
      getHeader in interface org.apache.hc.core5.http.MessageHeaders
      Throws:
      org.apache.hc.core5.http.ProtocolException
      Since:
      5.0
    • headerIterator

      public Iterator<org.apache.hc.core5.http.Header> headerIterator()
      Specified by:
      headerIterator in interface org.apache.hc.core5.http.MessageHeaders
      Since:
      5.0
    • headerIterator

      public Iterator<org.apache.hc.core5.http.Header> headerIterator(String name)
      Specified by:
      headerIterator in interface org.apache.hc.core5.http.MessageHeaders
      Since:
      5.0
    • responseHeaders

      public org.apache.hc.core5.http.MessageHeaders responseHeaders()
      Since:
      5.4
    • getDate

      public Date getDate()
      Gets the Date value of the "Date" header or null if the header is missing or cannot be parsed.
      Since:
      4.3
    • getInstant

      private Instant getInstant(AtomicReference<Instant> ref, String headerName)
    • getInstant

      public Instant getInstant()
      Since:
      5.2
    • getExpires

      public Instant getExpires()
      Since:
      5.4
    • getLastModified

      public Instant getLastModified()
      Since:
      5.4
    • getETag

      public ETag getETag()
      Since:
      5.4
    • getResource

      public Resource getResource()
      Returns the Resource containing the origin response body.
    • hasVariants

      public boolean hasVariants()
      Indicates whether the origin response indicated the associated resource had variants (i.e. that the Vary header was set on the origin response).
    • getVariants

      public Set<String> getVariants()
      Returns all known variants.
      Since:
      5.4
    • getVariantMap

      @Deprecated public Map<String,String> getVariantMap()
      Deprecated.
      No longer applicable. Use getVariants() instead.
    • getRequestMethod

      public String getRequestMethod()
      Returns the HTTP request method that was used to create the cached response entry.
      Since:
      4.4
    • getRequestURI

      public String getRequestURI()
      Since:
      5.4
    • requestHeaders

      public org.apache.hc.core5.http.MessageHeaders requestHeaders()
      Since:
      5.4
    • requestHeaderIterator

      public Iterator<org.apache.hc.core5.http.Header> requestHeaderIterator()
      Since:
      5.4
    • requestHeaderIterator

      public Iterator<org.apache.hc.core5.http.Header> requestHeaderIterator(String headerName)
      Since:
      5.4
    • isNewer

      public static boolean isNewer(HttpCacheEntry entry, org.apache.hc.core5.http.MessageHeaders message)
      Tests if the given HttpCacheEntry is newer than the given MessageHeaders by comparing values of their DATE header. In case the given entry, or the message, or their DATE headers are null, this method returns false.
      Since:
      5.4
    • toString

      public String toString()
      Provides a string representation of this instance suitable for human consumption.
      Overrides:
      toString in class Object