Package org.apache.http.client.cache
Class HttpCacheEntry
java.lang.Object
org.apache.http.client.cache.HttpCacheEntry
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionHttpCacheEntry
(Date requestDate, Date responseDate, StatusLine statusLine, Header[] responseHeaders, Resource resource) Create a newHttpCacheEntry
.HttpCacheEntry
(Date requestDate, Date responseDate, StatusLine statusLine, Header[] responseHeaders, Resource resource, String requestMethod) Create a newHttpCacheEntry
.HttpCacheEntry
(Date requestDate, Date responseDate, StatusLine statusLine, Header[] responseHeaders, Resource resource, Map<String, String> variantMap) Create a newHttpCacheEntry
with variants.HttpCacheEntry
(Date requestDate, Date responseDate, StatusLine statusLine, Header[] responseHeaders, Resource resource, Map<String, String> variantMap, String requestMethod) Create a newHttpCacheEntry
with variants. -
Method Summary
Modifier and TypeMethodDescriptionHeader[]
Returns all the headers that were on the origin response.getDate()
Gets the Date value of the "Date" header or null if the header is missing or cannot be parsed.getFirstHeader
(String name) Returns the first header from the origin response with the given name.Header[]
getHeaders
(String name) Gets all the headers with the given name that were on the origin response.Returns theProtocolVersion
from the originHttpResponse
.Gets the reason phrase from the originHttpResponse
, 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 theResource
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 originHttpResponse
.Returns theStatusLine
from the originHttpResponse
.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.toString()
Provides a string representation of this instance suitable for human consumption.
-
Constructor Details
-
HttpCacheEntry
public HttpCacheEntry(Date requestDate, Date responseDate, StatusLine statusLine, Header[] responseHeaders, Resource resource, Map<String, String> variantMap, String requestMethod) Create a newHttpCacheEntry
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 responseresponseHeaders
- Header[] from original HTTP Responseresource
- representing origin response bodyvariantMap
- 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, StatusLine statusLine, Header[] responseHeaders, Resource resource, Map<String, String> variantMap) Create a newHttpCacheEntry
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 responseresponseHeaders
- Header[] from original HTTP Responseresource
- representing origin response bodyvariantMap
- 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, StatusLine statusLine, Header[] responseHeaders, Resource resource) Create a newHttpCacheEntry
.- 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 responseresponseHeaders
- Header[] from original HTTP Responseresource
- representing origin response body
-
HttpCacheEntry
public HttpCacheEntry(Date requestDate, Date responseDate, StatusLine statusLine, Header[] responseHeaders, Resource resource, String requestMethod) Create a newHttpCacheEntry
.- 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 responseresponseHeaders
- Header[] from original HTTP Responseresource
- representing origin response bodyrequestMethod
- HTTP method used when the request was made
-
-
Method Details
-
getStatusLine
Returns theStatusLine
from the originHttpResponse
. -
getProtocolVersion
Returns theProtocolVersion
from the originHttpResponse
. -
getReasonPhrase
Gets the reason phrase from the originHttpResponse
, for example, "Not Modified". -
getStatusCode
public int getStatusCode()Returns the HTTP response code from the originHttpResponse
. -
getRequestDate
Returns the time the associated origin request was initiated by the caching module.- Returns:
Date
-
getResponseDate
Returns the time the origin response was received by the caching module.- Returns:
Date
-
getAllHeaders
Returns all the headers that were on the origin response. -
getFirstHeader
Returns the first header from the origin response with the given name. -
getHeaders
Gets all the headers with the given name that were on the origin response. -
getDate
Gets the Date value of the "Date" header or null if the header is missing or cannot be parsed.- Since:
- 4.3
-
getResource
Returns theResource
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
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 theHttpCacheStorage
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
Returns the HTTP request method that was used to create the cached response entry.- Since:
- 4.4
-
toString
Provides a string representation of this instance suitable for human consumption.
-