Class CacheKeyGenerator
- java.lang.Object
-
- org.apache.hc.client5.http.impl.cache.CacheKeyGenerator
-
- All Implemented Interfaces:
org.apache.hc.core5.function.Resolver<java.net.URI,java.lang.String>
@Contract(threading=STATELESS) public class CacheKeyGenerator extends java.lang.Object implements org.apache.hc.core5.function.Resolver<java.net.URI,java.lang.String>- Since:
- 4.1
-
-
Field Summary
Fields Modifier and Type Field Description static CacheKeyGeneratorINSTANCEDefault instance ofCacheKeyGenerator.
-
Constructor Summary
Constructors Constructor Description CacheKeyGenerator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.lang.StringgenerateKey(java.net.URI requestUri)Computes a key for the given requestURIthat can be used as a unique identifier for cached resources.java.lang.StringgenerateKey(org.apache.hc.core5.http.HttpHost host, org.apache.hc.core5.http.HttpRequest request)Computes a root key for the givenHttpHostandHttpRequestthat can be used as a unique identifier for cached resources.java.lang.StringgenerateKey(org.apache.hc.core5.http.HttpHost host, org.apache.hc.core5.http.HttpRequest request, HttpCacheEntry entry)Deprecated.java.lang.StringgenerateVariantKey(org.apache.hc.core5.http.HttpRequest request, java.util.Collection<java.lang.String> variantNames)Computes a "variant key" for the given request and the given variants.java.lang.StringgenerateVariantKey(org.apache.hc.core5.http.HttpRequest request, HttpCacheEntry entry)Computes a "variant key" from the headers of the given request if the given cache entry can have variants (Varyheader is present).static java.lang.StringgetRequestUri(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.HttpRequest request)Returns text representation of the request URI of the givenHttpRequest.static java.net.URInormalize(java.lang.String requestUri)Lenient URI parser that normalizes validURIs and returnsnullfor malformed URIs.static java.net.URInormalize(java.net.URI requestUri)Returns normalized representation of the request URI optimized for use as a cache key.static voidnormalizeElements(java.util.Iterator<org.apache.hc.core5.http.Header> iterator, java.util.function.Consumer<java.lang.String> consumer)static voidnormalizeElements(org.apache.hc.core5.http.MessageHeaders message, java.lang.String headerName, java.util.function.Consumer<java.lang.String> consumer)java.lang.Stringresolve(java.net.URI uri)static java.util.List<java.lang.String>variantNames(org.apache.hc.core5.http.MessageHeaders message)Returns all variant names contained in VARY headers of the given message.
-
-
-
Field Detail
-
INSTANCE
public static final CacheKeyGenerator INSTANCE
Default instance ofCacheKeyGenerator.
-
-
Method Detail
-
resolve
public java.lang.String resolve(java.net.URI uri)
- Specified by:
resolvein interfaceorg.apache.hc.core5.function.Resolver<java.net.URI,java.lang.String>
-
getRequestUri
@Internal public static java.lang.String getRequestUri(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.HttpRequest request)Returns text representation of the request URI of the givenHttpRequest. This method will useHttpRequest.getPath(),HttpRequest.getScheme()andHttpRequest.getAuthority()values when available or attributes of targetHttpHostin order to construct an absolute URI.This method will not attempt to ensure validity of the resultant text representation.
- Parameters:
target- target hostrequest- theHttpRequest- Returns:
- String the request URI
-
normalize
@Internal public static java.net.URI normalize(java.net.URI requestUri) throws java.net.URISyntaxExceptionReturns normalized representation of the request URI optimized for use as a cache key. This method ensures the resultant URI has an explicit port in the authority component, and explicit path component and no fragment.- Throws:
java.net.URISyntaxException
-
normalize
@Internal public static java.net.URI normalize(java.lang.String requestUri)
Lenient URI parser that normalizes validURIs and returnsnullfor malformed URIs.
-
generateKey
public java.lang.String generateKey(java.net.URI requestUri)
Computes a key for the given requestURIthat can be used as a unique identifier for cached resources. The URI is expected to in an absolute form.- Parameters:
requestUri- request URI- Returns:
- cache key
-
generateKey
public java.lang.String generateKey(org.apache.hc.core5.http.HttpHost host, org.apache.hc.core5.http.HttpRequest request)Computes a root key for the givenHttpHostandHttpRequestthat can be used as a unique identifier for cached resources.- Parameters:
host- The host for this requestrequest- theHttpRequest- Returns:
- cache key
-
variantNames
public static java.util.List<java.lang.String> variantNames(org.apache.hc.core5.http.MessageHeaders message)
Returns all variant names contained in VARY headers of the given message.- Since:
- 5.4
-
normalizeElements
@Internal public static void normalizeElements(org.apache.hc.core5.http.MessageHeaders message, java.lang.String headerName, java.util.function.Consumer<java.lang.String> consumer)
-
normalizeElements
@Internal public static void normalizeElements(java.util.Iterator<org.apache.hc.core5.http.Header> iterator, java.util.function.Consumer<java.lang.String> consumer)
-
generateVariantKey
public java.lang.String generateVariantKey(org.apache.hc.core5.http.HttpRequest request, java.util.Collection<java.lang.String> variantNames)Computes a "variant key" for the given request and the given variants.- Parameters:
request- originating requestvariantNames- variant names- Returns:
- variant key
- Since:
- 5.4
-
generateVariantKey
public java.lang.String generateVariantKey(org.apache.hc.core5.http.HttpRequest request, HttpCacheEntry entry)Computes a "variant key" from the headers of the given request if the given cache entry can have variants (Varyheader is present).- Parameters:
request- originating requestentry- cache entry- Returns:
- variant key if the given cache entry can have variants,
nullotherwise.
-
generateKey
@Deprecated public java.lang.String generateKey(org.apache.hc.core5.http.HttpHost host, org.apache.hc.core5.http.HttpRequest request, HttpCacheEntry entry)Deprecated.Computes a key for the givenHttpHostandHttpRequestthat can be used as a unique identifier for cached resources. if the request has a VARY header the identifier will also include variant key.- Parameters:
host- The host for this requestrequest- theHttpRequestentry- the parent entry used to track the variants- Returns:
- cache key
-
-