org.apache.hc.client5.http.cache

## 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:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `HttpCacheEntry(Date requestDate, Date responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource)` Deprecated. {`HttpCacheEntry(Instant, Instant, int, Header[], Resource)`}
    `HttpCacheEntry(Date requestDate, Date responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource, Map<String,String> variantMap)` Deprecated. Use {`HttpCacheEntry(Instant, Instant, int, Header[], Resource, Map)`}
    `HttpCacheEntry(Instant requestDate, Instant responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource)` Create a new `HttpCacheEntry`.
    `HttpCacheEntry(Instant requestDate, Instant responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource, Map<String,String> variantMap)` Create a new `HttpCacheEntry` with variants.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `containsHeader(String name)`
    `int` | `countHeaders(String name)`
    `Date` | `getDate()` Gets the Date value of the "Date" header or null if the header is missing or cannot be parsed.
    `org.apache.hc.core5.http.Header` | `getFirstHeader(String name)` Returns the first header from the origin response with the given name.
    `org.apache.hc.core5.http.Header` | `getHeader(String name)`
    `org.apache.hc.core5.http.Header[]` | `getHeaders()` Returns all the headers that were on the origin response.
    `org.apache.hc.core5.http.Header[]` | `getHeaders(String name)` Gets all the headers with the given name that were on the origin response.
    `Instant` | `getInstant()`
    `org.apache.hc.core5.http.Header` | `getLastHeader(String name)`
    `Date` | `getRequestDate()` Deprecated. USe `getRequestInstant()`
    `Instant` | `getRequestInstant()` Returns the time the associated origin request was initiated by the caching module.
    `String` | `getRequestMethod()` Returns the HTTP request method that was used to create the cached response entry.
    `Resource` | `getResource()` Returns the `Resource` containing the origin response body.
    `Date` | `getResponseDate()` Deprecated. Use `getResponseInstant()`
    `Instant` | `getResponseInstant()` Returns the time the origin response was received by the caching module.
    `int` | `getStatus()` Returns the status from the origin `HttpResponse`.
    `Map<String,String>` | `getVariantMap()` Returns an index about where in the cache different variants for a given resource are stored.
    `boolean` | `hasVariants()` Indicates whether the origin response indicated the associated resource had variants (i.e.
    `Iterator<org.apache.hc.core5.http.Header>` | `headerIterator()`
    `Iterator<org.apache.hc.core5.http.Header>` | `headerIterator(String name)`
    `String` | `toString()` Provides a string representation of this instance suitable for human consumption.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### HttpCacheEntry

          @Deprecated
          public HttpCacheEntry(Date requestDate,
                                            Date responseDate,
                                            int status,
                                            org.apache.hc.core5.http.Header[] responseHeaders,
                                            Resource resource,
                                            Map<String,String> variantMap)

      Deprecated. Use {`HttpCacheEntry(Instant, Instant, int, Header[], Resource, Map)`}
      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

          public HttpCacheEntry(Instant requestDate,
                                Instant responseDate,
                                int status,
                                org.apache.hc.core5.http.Header[] responseHeaders,
                                Resource resource,
                                Map<String,String> variantMap)

      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)
      Since:
        5.2

    - #### HttpCacheEntry

          @Deprecated
          public HttpCacheEntry(Date requestDate,
                                            Date responseDate,
                                            int status,
                                            org.apache.hc.core5.http.Header[] responseHeaders,
                                            Resource resource)

      Deprecated. {`HttpCacheEntry(Instant, Instant, int, Header[], Resource)`}
      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

          public HttpCacheEntry(Instant requestDate,
                                Instant responseDate,
                                int status,
                                org.apache.hc.core5.http.Header[] responseHeaders,
                                Resource resource)

      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 Detail

    - #### getStatus

          public int getStatus()

      Returns the status from the origin `HttpResponse`.

    - #### getRequestDate

          @Deprecated
          public Date getRequestDate()

      Deprecated. USe `getRequestInstant()`
      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. Use `getResponseInstant()`
      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

    - #### 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

          public Instant getInstant()

    - #### 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).
      Returns:
        `true` if this cached response was a variant

    - #### getVariantMap

          public Map<String,String> getVariantMap()

      Returns an index about where in the cache different variants for a given resource are stored. This maps "variant keys" to "cache keys", where the variant key is derived from the varying request headers, and the cache key is the location in the `HttpCacheStorage` where that particular variant is stored. The first variant returned is used as the "parent" entry to hold this index of the other variants.

    - #### getRequestMethod

          public String getRequestMethod()

      Returns the HTTP request method that was used to create the cached response entry.
      Since:
        4.4

    - #### toString

          public String toString()

      Provides a string representation of this instance suitable for human consumption.
      Overrides:
        `toString` in class `Object`

Copyright © 1999–2021 The Apache Software Foundation. All rights reserved.