Package org.apache.http.client.cache
Class HttpCacheEntry
- java.lang.Object
-
- org.apache.http.client.cache.HttpCacheEntry
-
- All Implemented Interfaces:
java.io.Serializable
@Contract(threading=IMMUTABLE) public class HttpCacheEntry extends java.lang.Object implements java.io.Serializable
Structure used to store anHttpResponse
in a cache. Some entries can optionally depend on system resources that may require explicit deallocation. In such a casegetResource()
should return a non null instance ofResource
that must be deallocated by callingResource.dispose()
method when no longer used.- Since:
- 4.1
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description HttpCacheEntry(java.util.Date requestDate, java.util.Date responseDate, StatusLine statusLine, Header[] responseHeaders, Resource resource)
Create a newHttpCacheEntry
.HttpCacheEntry(java.util.Date requestDate, java.util.Date responseDate, StatusLine statusLine, Header[] responseHeaders, Resource resource, java.lang.String requestMethod)
Create a newHttpCacheEntry
.HttpCacheEntry(java.util.Date requestDate, java.util.Date responseDate, StatusLine statusLine, Header[] responseHeaders, Resource resource, java.util.Map<java.lang.String,java.lang.String> variantMap)
Create a newHttpCacheEntry
with variants.HttpCacheEntry(java.util.Date requestDate, java.util.Date responseDate, StatusLine statusLine, Header[] responseHeaders, Resource resource, java.util.Map<java.lang.String,java.lang.String> variantMap, java.lang.String requestMethod)
Create a newHttpCacheEntry
with variants.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Header[]
getAllHeaders()
Returns all the headers that were on the origin response.java.util.Date
getDate()
Gets the Date value of the "Date" header or null if the header is missing or cannot be parsed.Header
getFirstHeader(java.lang.String name)
Returns the first header from the origin response with the given name.Header[]
getHeaders(java.lang.String name)
Gets all the headers with the given name that were on the origin response.ProtocolVersion
getProtocolVersion()
Returns theProtocolVersion
from the originHttpResponse
.java.lang.String
getReasonPhrase()
Gets the reason phrase from the originHttpResponse
, for example, "Not Modified".java.util.Date
getRequestDate()
Returns the time the associated origin request was initiated by the caching module.java.lang.String
getRequestMethod()
Returns the HTTP request method that was used to create the cached response entry.Resource
getResource()
Returns theResource
containing the origin response body.java.util.Date
getResponseDate()
Returns the time the origin response was received by the caching module.int
getStatusCode()
Returns the HTTP response code from the originHttpResponse
.StatusLine
getStatusLine()
Returns theStatusLine
from the originHttpResponse
.java.util.Map<java.lang.String,java.lang.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.java.lang.String
toString()
Provides a string representation of this instance suitable for human consumption.
-
-
-
Constructor Detail
-
HttpCacheEntry
public HttpCacheEntry(java.util.Date requestDate, java.util.Date responseDate, StatusLine statusLine, Header[] responseHeaders, Resource resource, java.util.Map<java.lang.String,java.lang.String> variantMap, java.lang.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(java.util.Date requestDate, java.util.Date responseDate, StatusLine statusLine, Header[] responseHeaders, Resource resource, java.util.Map<java.lang.String,java.lang.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(java.util.Date requestDate, java.util.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(java.util.Date requestDate, java.util.Date responseDate, StatusLine statusLine, Header[] responseHeaders, Resource resource, java.lang.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 Detail
-
getStatusLine
public StatusLine getStatusLine()
Returns theStatusLine
from the originHttpResponse
.
-
getProtocolVersion
public ProtocolVersion getProtocolVersion()
Returns theProtocolVersion
from the originHttpResponse
.
-
getReasonPhrase
public java.lang.String 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
public java.util.Date getRequestDate()
Returns the time the associated origin request was initiated by the caching module.- Returns:
Date
-
getResponseDate
public java.util.Date getResponseDate()
Returns the time the origin response was received by the caching module.- Returns:
Date
-
getAllHeaders
public Header[] getAllHeaders()
Returns all the headers that were on the origin response.
-
getFirstHeader
public Header getFirstHeader(java.lang.String name)
Returns the first header from the origin response with the given name.
-
getHeaders
public Header[] getHeaders(java.lang.String name)
Gets all the headers with the given name that were on the origin response.
-
getDate
public java.util.Date getDate()
Gets the Date value of the "Date" header or null if the header is missing or cannot be parsed.- Since:
- 4.3
-
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 java.util.Map<java.lang.String,java.lang.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 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
public java.lang.String getRequestMethod()
Returns the HTTP request method that was used to create the cached response entry.- Since:
- 4.4
-
toString
public java.lang.String toString()
Provides a string representation of this instance suitable for human consumption.- Overrides:
toString
in classjava.lang.Object
-
-