Class HttpCacheEntry

java.lang.Object
org.apache.http.client.cache.HttpCacheEntry
All Implemented Interfaces:
Serializable

@Contract(threading=IMMUTABLE) public class HttpCacheEntry extends Object implements 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:
  • Constructor Summary

    Constructors
    Constructor
    Description
    HttpCacheEntry(Date requestDate, Date responseDate, org.apache.http.StatusLine statusLine, org.apache.http.Header[] responseHeaders, Resource resource)
    Create a new HttpCacheEntry.
    HttpCacheEntry(Date requestDate, Date responseDate, org.apache.http.StatusLine statusLine, org.apache.http.Header[] responseHeaders, Resource resource, String requestMethod)
    Create a new HttpCacheEntry.
    HttpCacheEntry(Date requestDate, Date responseDate, org.apache.http.StatusLine statusLine, org.apache.http.Header[] responseHeaders, Resource resource, Map<String,String> variantMap)
    Create a new HttpCacheEntry with variants.
    HttpCacheEntry(Date requestDate, Date responseDate, org.apache.http.StatusLine statusLine, org.apache.http.Header[] responseHeaders, Resource resource, Map<String,String> variantMap, String requestMethod)
    Create a new HttpCacheEntry with variants.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.http.Header[]
    Returns all the headers that were on the origin response.
    Gets the Date value of the "Date" header or null if the header is missing or cannot be parsed.
    org.apache.http.Header
    Returns the first header from the origin response with the given name.
    org.apache.http.Header[]
    Gets all the headers with the given name that were on the origin response.
    org.apache.http.ProtocolVersion
    Returns the ProtocolVersion from the origin HttpResponse.
    Gets the reason phrase from the origin HttpResponse, for example, "Not Modified".
    Returns the time the associated origin request was initiated by the caching module.
    Returns the HTTP request method that was used to create the cached response entry.
    Returns the Resource containing the origin response body.
    Returns the time the origin response was received by the caching module.
    int
    Returns the HTTP response code from the origin HttpResponse.
    org.apache.http.StatusLine
    Returns the StatusLine from the origin HttpResponse.
    Returns an index about where in the cache different variants for a given resource are stored.
    boolean
    Indicates whether the origin response indicated the associated resource had variants (i.e.
    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 Details

    • HttpCacheEntry

      public HttpCacheEntry(Date requestDate, Date responseDate, org.apache.http.StatusLine statusLine, org.apache.http.Header[] responseHeaders, Resource resource, Map<String,String> variantMap, String requestMethod)
      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)
      statusLine - HTTP status line 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)
      requestMethod - HTTP method used when the request was made
    • HttpCacheEntry

      public HttpCacheEntry(Date requestDate, Date responseDate, org.apache.http.StatusLine statusLine, org.apache.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)
      statusLine - HTTP status line 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(Date requestDate, Date responseDate, org.apache.http.StatusLine statusLine, org.apache.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)
      statusLine - HTTP status line from origin response
      responseHeaders - Header[] from original HTTP Response
      resource - representing origin response body
    • HttpCacheEntry

      public HttpCacheEntry(Date requestDate, Date responseDate, org.apache.http.StatusLine statusLine, org.apache.http.Header[] responseHeaders, Resource resource, String requestMethod)
      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)
      statusLine - HTTP status line from origin response
      responseHeaders - Header[] from original HTTP Response
      resource - representing origin response body
      requestMethod - HTTP method used when the request was made
  • Method Details

    • getStatusLine

      public org.apache.http.StatusLine getStatusLine()
      Returns the StatusLine from the origin HttpResponse.
    • getProtocolVersion

      public org.apache.http.ProtocolVersion getProtocolVersion()
      Returns the ProtocolVersion from the origin HttpResponse.
    • getReasonPhrase

      public String getReasonPhrase()
      Gets the reason phrase from the origin HttpResponse, for example, "Not Modified".
    • getStatusCode

      public int getStatusCode()
      Returns the HTTP response code from the origin HttpResponse.
    • getRequestDate

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

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

      public org.apache.http.Header[] getAllHeaders()
      Returns all the headers that were on the origin response.
    • getFirstHeader

      public org.apache.http.Header getFirstHeader(String name)
      Returns the first header from the origin response with the given name.
    • getHeaders

      public org.apache.http.Header[] getHeaders(String name)
      Gets all the headers with the given name that were on the origin response.
    • 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
    • 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