Class 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
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      java.lang.String generateKey​(java.net.URI requestUri)
      Computes a key for the given request URI that can be used as a unique identifier for cached resources.
      java.lang.String generateKey​(org.apache.hc.core5.http.HttpHost host, org.apache.hc.core5.http.HttpRequest request)
      Computes a root key for the given HttpHost and HttpRequest that can be used as a unique identifier for cached resources.
      java.lang.String generateKey​(org.apache.hc.core5.http.HttpHost host, org.apache.hc.core5.http.HttpRequest request, HttpCacheEntry entry)
      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.
      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 (Vary header is present).
      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 given HttpRequest.
      static java.net.URI normalize​(java.lang.String requestUri)
      Lenient URI parser that normalizes valid URIs and returns null for malformed URIs.
      static java.net.URI normalize​(java.net.URI requestUri)
      Returns normalized representation of the request URI optimized for use as a cache key.
      static void normalizeElements​(java.util.Iterator<org.apache.hc.core5.http.Header> iterator, java.util.function.Consumer<java.lang.String> consumer)  
      static void normalizeElements​(org.apache.hc.core5.http.MessageHeaders message, java.lang.String headerName, java.util.function.Consumer<java.lang.String> consumer)  
      java.lang.String resolve​(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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CacheKeyGenerator

        public CacheKeyGenerator()
    • Method Detail

      • resolve

        public java.lang.String resolve​(java.net.URI uri)
        Specified by:
        resolve in interface org.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 given HttpRequest. This method will use HttpRequest.getPath(), HttpRequest.getScheme() and HttpRequest.getAuthority() values when available or attributes of target HttpHost in order to construct an absolute URI.

        This method will not attempt to ensure validity of the resultant text representation.

        Parameters:
        target - target host
        request - the HttpRequest
        Returns:
        String the request URI
      • normalize

        @Internal
        public static java.net.URI normalize​(java.net.URI requestUri)
                                      throws java.net.URISyntaxException
        Returns 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 valid URIs and returns null for malformed URIs.
      • generateKey

        public java.lang.String generateKey​(java.net.URI requestUri)
        Computes a key for the given request URI that 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 given HttpHost and HttpRequest that can be used as a unique identifier for cached resources.
        Parameters:
        host - The host for this request
        request - the HttpRequest
        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 request
        variantNames - 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 (Vary header is present).
        Parameters:
        request - originating request
        entry - cache entry
        Returns:
        variant key if the given cache entry can have variants, null otherwise.
      • generateKey

        @Deprecated
        public java.lang.String generateKey​(org.apache.hc.core5.http.HttpHost host,
                                            org.apache.hc.core5.http.HttpRequest request,
                                            HttpCacheEntry entry)
        Computes a key for the given HttpHost and HttpRequest that 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 request
        request - the HttpRequest
        entry - the parent entry used to track the variants
        Returns:
        cache key