Package org.apache.hc.client5.http.cache
Class HttpCacheEntry
- java.lang.Object
-
- org.apache.hc.client5.http.cache.HttpCacheEntry
-
- All Implemented Interfaces:
java.io.Serializable
,org.apache.hc.core5.http.MessageHeaders
@Contract(threading=IMMUTABLE) public class HttpCacheEntry extends java.lang.Object implements org.apache.hc.core5.http.MessageHeaders, 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
-
-
Field Summary
Fields Modifier and Type Field Description private java.time.Instant
date
private static java.lang.String
REQUEST_METHOD_HEADER_NAME
private java.time.Instant
requestDate
private Resource
resource
private java.time.Instant
responseDate
private org.apache.hc.core5.http.message.HeaderGroup
responseHeaders
private static long
serialVersionUID
private int
status
private java.util.Map<java.lang.String,java.lang.String>
variantMap
-
Constructor Summary
Constructors Constructor Description HttpCacheEntry(java.time.Instant requestDate, java.time.Instant responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource)
Create a newHttpCacheEntry
.HttpCacheEntry(java.time.Instant requestDate, java.time.Instant responseDate, int status, org.apache.hc.core5.http.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, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource)
HttpCacheEntry(java.util.Date requestDate, java.util.Date responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource, java.util.Map<java.lang.String,java.lang.String> variantMap)
Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
containsHeader(java.lang.String name)
int
countHeaders(java.lang.String name)
java.util.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(java.lang.String name)
Returns the first header from the origin response with the given name.org.apache.hc.core5.http.Header
getHeader(java.lang.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(java.lang.String name)
Gets all the headers with the given name that were on the origin response.java.time.Instant
getInstant()
org.apache.hc.core5.http.Header
getLastHeader(java.lang.String name)
java.util.Date
getRequestDate()
Deprecated.java.time.Instant
getRequestInstant()
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()
Deprecated.java.time.Instant
getResponseInstant()
Returns the time the origin response was received by the caching module.int
getStatus()
Returns the status 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.util.Iterator<org.apache.hc.core5.http.Header>
headerIterator()
java.util.Iterator<org.apache.hc.core5.http.Header>
headerIterator(java.lang.String name)
private java.time.Instant
parseDate()
Find the "Date" response header and parse it into aInstant
java.lang.String
toString()
Provides a string representation of this instance suitable for human consumption.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
REQUEST_METHOD_HEADER_NAME
private static final java.lang.String REQUEST_METHOD_HEADER_NAME
- See Also:
- Constant Field Values
-
requestDate
private final java.time.Instant requestDate
-
responseDate
private final java.time.Instant responseDate
-
status
private final int status
-
responseHeaders
private final org.apache.hc.core5.http.message.HeaderGroup responseHeaders
-
resource
private final Resource resource
-
variantMap
private final java.util.Map<java.lang.String,java.lang.String> variantMap
-
date
private final java.time.Instant date
-
-
Constructor Detail
-
HttpCacheEntry
@Deprecated public HttpCacheEntry(java.util.Date requestDate, java.util.Date responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource, java.util.Map<java.lang.String,java.lang.String> variantMap)
Deprecated.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)status
- HTTP status 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.time.Instant requestDate, java.time.Instant responseDate, int status, org.apache.hc.core5.http.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)status
- HTTP status 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)- Since:
- 5.2
-
HttpCacheEntry
@Deprecated public HttpCacheEntry(java.util.Date requestDate, java.util.Date responseDate, int status, org.apache.hc.core5.http.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)status
- HTTP status from origin responseresponseHeaders
- Header[] from original HTTP Responseresource
- representing origin response body
-
HttpCacheEntry
public HttpCacheEntry(java.time.Instant requestDate, java.time.Instant responseDate, int status, org.apache.hc.core5.http.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)status
- HTTP status from origin responseresponseHeaders
- Header[] from original HTTP Responseresource
- representing origin response body
-
-
Method Detail
-
parseDate
private java.time.Instant parseDate()
Find the "Date" response header and parse it into aInstant
- Returns:
- the Date value of the header or null if the header is not present
-
getStatus
public int getStatus()
Returns the status from the originHttpResponse
.
-
getRequestDate
@Deprecated public java.util.Date getRequestDate()
Deprecated.Returns the time the associated origin request was initiated by the caching module.- Returns:
Date
-
getRequestInstant
public java.time.Instant getRequestInstant()
Returns the time the associated origin request was initiated by the caching module.- Returns:
Instant
- Since:
- 5.2
-
getResponseDate
@Deprecated public java.util.Date getResponseDate()
Deprecated.Returns the time the origin response was received by the caching module.- Returns:
Date
-
getResponseInstant
public java.time.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 interfaceorg.apache.hc.core5.http.MessageHeaders
-
getFirstHeader
public org.apache.hc.core5.http.Header getFirstHeader(java.lang.String name)
Returns the first header from the origin response with the given name.- Specified by:
getFirstHeader
in interfaceorg.apache.hc.core5.http.MessageHeaders
-
getLastHeader
public org.apache.hc.core5.http.Header getLastHeader(java.lang.String name)
- Specified by:
getLastHeader
in interfaceorg.apache.hc.core5.http.MessageHeaders
- Since:
- 5.0
-
getHeaders
public org.apache.hc.core5.http.Header[] getHeaders(java.lang.String name)
Gets all the headers with the given name that were on the origin response.- Specified by:
getHeaders
in interfaceorg.apache.hc.core5.http.MessageHeaders
-
containsHeader
public boolean containsHeader(java.lang.String name)
- Specified by:
containsHeader
in interfaceorg.apache.hc.core5.http.MessageHeaders
- Since:
- 5.0
-
countHeaders
public int countHeaders(java.lang.String name)
- Specified by:
countHeaders
in interfaceorg.apache.hc.core5.http.MessageHeaders
- Since:
- 5.0
-
getHeader
public org.apache.hc.core5.http.Header getHeader(java.lang.String name) throws org.apache.hc.core5.http.ProtocolException
- Specified by:
getHeader
in interfaceorg.apache.hc.core5.http.MessageHeaders
- Throws:
org.apache.hc.core5.http.ProtocolException
- Since:
- 5.0
-
headerIterator
public java.util.Iterator<org.apache.hc.core5.http.Header> headerIterator()
- Specified by:
headerIterator
in interfaceorg.apache.hc.core5.http.MessageHeaders
- Since:
- 5.0
-
headerIterator
public java.util.Iterator<org.apache.hc.core5.http.Header> headerIterator(java.lang.String name)
- Specified by:
headerIterator
in interfaceorg.apache.hc.core5.http.MessageHeaders
- Since:
- 5.0
-
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
-
getInstant
public java.time.Instant getInstant()
-
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
-
-