Class HttpCacheEntry
java.lang.Object
org.apache.hc.client5.http.cache.HttpCacheEntry
- All Implemented Interfaces:
Serializable, org.apache.hc.core5.http.MessageHeaders
@Contract(threading=IMMUTABLE)
public class HttpCacheEntry
extends Object
implements org.apache.hc.core5.http.MessageHeaders, 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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicReference<Instant> private final AtomicReference<ETag> private final AtomicReference<Instant> private final AtomicReference<Instant> private final Stringprivate static final Instantprivate final Instantprivate final org.apache.hc.core5.http.message.HeaderGroupprivate final Stringprivate final Resourceprivate final Instantprivate final org.apache.hc.core5.http.message.HeaderGroupprivate static final longprivate final int -
Constructor Summary
ConstructorsConstructorDescriptionHttpCacheEntry(Instant requestDate, Instant responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource) Deprecated.HttpCacheEntry(Instant requestDate, Instant responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource, Map<String, String> variantMap) Deprecated.HttpCacheEntry(Instant requestDate, Instant responseDate, String method, String requestURI, org.apache.hc.core5.http.message.HeaderGroup requestHeaders, int status, org.apache.hc.core5.http.message.HeaderGroup responseHeaders, Resource resource, Collection<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(Date requestDate, Date responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource) Deprecated.HttpCacheEntry(Date requestDate, Date responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource, Map<String, String> variantMap) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsHeader(String name) intcountHeaders(String name) getDate()Gets the Date value of the "Date" header or null if the header is missing or cannot be parsed.getETag()org.apache.hc.core5.http.HeadergetFirstHeader(String name) Returns the first header from the origin response with the given name.org.apache.hc.core5.http.Headerorg.apache.hc.core5.http.Header[]Returns all the headers that were on the origin response.org.apache.hc.core5.http.Header[]getHeaders(String name) Gets all the headers with the given name that were on the origin response.private InstantgetInstant(AtomicReference<Instant> ref, String headerName) org.apache.hc.core5.http.HeadergetLastHeader(String name) Deprecated.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 theResourcecontaining the origin response body.Deprecated.Returns the time the origin response was received by the caching module.intReturns the status from the originHttpResponse.Deprecated.No longer applicable.Returns all known variants.booleanIndicates whether the origin response indicated the associated resource had variants (i.e.Iterator<org.apache.hc.core5.http.Header> Iterator<org.apache.hc.core5.http.Header> headerIterator(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.Iterator<org.apache.hc.core5.http.Header> Iterator<org.apache.hc.core5.http.Header> requestHeaderIterator(String headerName) org.apache.hc.core5.http.MessageHeadersorg.apache.hc.core5.http.MessageHeaderstoString()Provides a string representation of this instance suitable for human consumption.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
requestDate
-
responseDate
-
method
-
requestURI
-
requestHeaders
private final org.apache.hc.core5.http.message.HeaderGroup requestHeaders -
status
private final int status -
responseHeaders
private final org.apache.hc.core5.http.message.HeaderGroup responseHeaders -
resource
-
variants
-
dateRef
-
expiresRef
-
lastModifiedRef
-
eTagRef
-
NON_VALUE
-
-
Constructor Details
-
HttpCacheEntry
@Internal public HttpCacheEntry(Instant requestDate, Instant responseDate, String method, String requestURI, org.apache.hc.core5.http.message.HeaderGroup requestHeaders, int status, org.apache.hc.core5.http.message.HeaderGroup responseHeaders, Resource resource, Collection<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(Date requestDate, Date responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource, Map<String, 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(Instant requestDate, Instant responseDate, int status, org.apache.hc.core5.http.Header[] responseHeaders, Resource resource, Map<String, 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(Date requestDate, 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(Instant requestDate, 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 Details
-
getStatus
public int getStatus()Returns the status from the originHttpResponse. -
getRequestDate
Deprecated.Returns the time the associated origin request was initiated by the caching module.- Returns:
Date
-
getRequestInstant
-
getResponseDate
-
getResponseInstant
-
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
Returns the first header from the origin response with the given name.- Specified by:
getFirstHeaderin interfaceorg.apache.hc.core5.http.MessageHeaders
-
getLastHeader
- Specified by:
getLastHeaderin interfaceorg.apache.hc.core5.http.MessageHeaders- Since:
- 5.0
-
getHeaders
Gets all the headers with the given name that were on the origin response.- Specified by:
getHeadersin interfaceorg.apache.hc.core5.http.MessageHeaders
-
containsHeader
- Specified by:
containsHeaderin interfaceorg.apache.hc.core5.http.MessageHeaders- Since:
- 5.0
-
countHeaders
- Specified by:
countHeadersin interfaceorg.apache.hc.core5.http.MessageHeaders- Since:
- 5.0
-
getHeader
public org.apache.hc.core5.http.Header getHeader(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
- Specified by:
headerIteratorin interfaceorg.apache.hc.core5.http.MessageHeaders- Since:
- 5.0
-
headerIterator
-
responseHeaders
public org.apache.hc.core5.http.MessageHeaders responseHeaders()- Since:
- 5.4
-
getDate
Gets the Date value of the "Date" header or null if the header is missing or cannot be parsed.- Since:
- 4.3
-
getInstant
-
getInstant
- Since:
- 5.2
-
getExpires
- Since:
- 5.4
-
getLastModified
- Since:
- 5.4
-
getETag
- Since:
- 5.4
-
getResource
-
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
-
getVariantMap
Deprecated.No longer applicable. UsegetVariants()instead. -
getRequestMethod
Returns the HTTP request method that was used to create the cached response entry.- Since:
- 4.4
-
getRequestURI
- Since:
- 5.4
-
requestHeaders
public org.apache.hc.core5.http.MessageHeaders requestHeaders()- Since:
- 5.4
-
requestHeaderIterator
- Since:
- 5.4
-
requestHeaderIterator
-
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
-
HttpCacheEntryFactory