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.SerializableStructure used to store anHttpResponsein 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 ofResourcethat 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.time.Instant requestDate, java.time.Instant responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource)Deprecated.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)Deprecated.HttpCacheEntry(java.time.Instant requestDate, java.time.Instant responseDate, java.lang.String method, java.lang.String requestURI, org.apache.hc.core5.http.message.HeaderGroup requestHeaders, int status, org.apache.hc.core5.http.message.HeaderGroup responseHeaders, Resource resource, java.util.Collection<java.lang.String> variants)Internal constructor that makes no validation of the input parameters and makes no copies of the original client request and the origin response.HttpCacheEntry(java.util.Date requestDate, java.util.Date responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource)Deprecated.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 Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancontainsHeader(java.lang.String name)intcountHeaders(java.lang.String name)java.util.DategetDate()Gets the Date value of the "Date" header or null if the header is missing or cannot be parsed.org.apache.hc.client5.http.validator.ETaggetETag()java.time.InstantgetExpires()org.apache.hc.core5.http.HeadergetFirstHeader(java.lang.String name)Returns the first header from the origin response with the given name.org.apache.hc.core5.http.HeadergetHeader(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.InstantgetInstant()org.apache.hc.core5.http.HeadergetLastHeader(java.lang.String name)java.time.InstantgetLastModified()java.util.DategetRequestDate()Deprecated.java.time.InstantgetRequestInstant()Returns the time the associated origin request was initiated by the caching module.java.lang.StringgetRequestMethod()Returns the HTTP request method that was used to create the cached response entry.java.lang.StringgetRequestURI()ResourcegetResource()Returns theResourcecontaining the origin response body.java.util.DategetResponseDate()Deprecated.java.time.InstantgetResponseInstant()Returns the time the origin response was received by the caching module.intgetStatus()Returns the status from the originHttpResponse.java.util.Map<java.lang.String,java.lang.String>getVariantMap()Deprecated.No longer applicable.java.util.Set<java.lang.String>getVariants()Returns all known variants.booleanhasVariants()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)static booleanisNewer(HttpCacheEntry entry, org.apache.hc.core5.http.MessageHeaders message)Tests if the givenHttpCacheEntryis newer than the givenMessageHeadersby comparing values of their DATE header.java.util.Iterator<org.apache.hc.core5.http.Header>requestHeaderIterator()java.util.Iterator<org.apache.hc.core5.http.Header>requestHeaderIterator(java.lang.String headerName)org.apache.hc.core5.http.MessageHeadersrequestHeaders()org.apache.hc.core5.http.MessageHeadersresponseHeaders()java.lang.StringtoString()Provides a string representation of this instance suitable for human consumption.
-
-
-
Constructor Detail
-
HttpCacheEntry
@Internal public HttpCacheEntry(java.time.Instant requestDate, java.time.Instant responseDate, java.lang.String method, java.lang.String requestURI, org.apache.hc.core5.http.message.HeaderGroup requestHeaders, int status, org.apache.hc.core5.http.message.HeaderGroup responseHeaders, Resource resource, java.util.Collection<java.lang.String> variants)Internal constructor that makes no validation of the input parameters and makes no copies of the original client request and the origin response.
-
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 newHttpCacheEntrywith 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
@Deprecated 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)Deprecated.Create a newHttpCacheEntrywith 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
@Deprecated public HttpCacheEntry(java.util.Date requestDate, java.util.Date responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource)Deprecated.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
@Deprecated public HttpCacheEntry(java.time.Instant requestDate, java.time.Instant responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource)Deprecated.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
-
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:
getHeadersin 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:
getFirstHeaderin interfaceorg.apache.hc.core5.http.MessageHeaders
-
getLastHeader
public org.apache.hc.core5.http.Header getLastHeader(java.lang.String name)
- Specified by:
getLastHeaderin 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:
getHeadersin interfaceorg.apache.hc.core5.http.MessageHeaders
-
containsHeader
public boolean containsHeader(java.lang.String name)
- Specified by:
containsHeaderin interfaceorg.apache.hc.core5.http.MessageHeaders- Since:
- 5.0
-
countHeaders
public int countHeaders(java.lang.String name)
- Specified by:
countHeadersin 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:
getHeaderin 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:
headerIteratorin 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:
headerIteratorin interfaceorg.apache.hc.core5.http.MessageHeaders- Since:
- 5.0
-
responseHeaders
public org.apache.hc.core5.http.MessageHeaders responseHeaders()
- Since:
- 5.4
-
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()
- Since:
- 5.2
-
getExpires
public java.time.Instant getExpires()
- Since:
- 5.4
-
getLastModified
public java.time.Instant getLastModified()
- Since:
- 5.4
-
getETag
public org.apache.hc.client5.http.validator.ETag getETag()
- Since:
- 5.4
-
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).
-
getVariants
public java.util.Set<java.lang.String> getVariants()
Returns all known variants.- Since:
- 5.4
-
getVariantMap
@Deprecated public java.util.Map<java.lang.String,java.lang.String> getVariantMap()
Deprecated.No longer applicable. UsegetVariants()instead.
-
getRequestMethod
public java.lang.String getRequestMethod()
Returns the HTTP request method that was used to create the cached response entry.- Since:
- 4.4
-
getRequestURI
public java.lang.String getRequestURI()
- Since:
- 5.4
-
requestHeaders
public org.apache.hc.core5.http.MessageHeaders requestHeaders()
- Since:
- 5.4
-
requestHeaderIterator
public java.util.Iterator<org.apache.hc.core5.http.Header> requestHeaderIterator()
- Since:
- 5.4
-
requestHeaderIterator
public java.util.Iterator<org.apache.hc.core5.http.Header> requestHeaderIterator(java.lang.String headerName)
- Since:
- 5.4
-
isNewer
public static boolean isNewer(HttpCacheEntry entry, org.apache.hc.core5.http.MessageHeaders message)
Tests if the givenHttpCacheEntryis newer than the givenMessageHeadersby comparing values of their DATE header. In case the given entry, or the message, or their DATE headers are null, this method returnsfalse.- Since:
- 5.4
-
toString
public java.lang.String toString()
Provides a string representation of this instance suitable for human consumption.- Overrides:
toStringin classjava.lang.Object
-
-