org.apache.hc.client5.http.impl.cache

## Class CacheKeyGenerator

- java.lang.Object
- - org.apache.hc.client5.http.impl.cache.CacheKeyGenerator

- All Implemented Interfaces:
    org.apache.hc.core5.function.Resolver<URI,String>

      @Contract(threading=STATELESS)
      public class CacheKeyGenerator
      extends Object
      implements org.apache.hc.core5.function.Resolver<URI,String>

  Since:
    4.1

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static CacheKeyGenerator` | `INSTANCE` Default instance of `CacheKeyGenerator`.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CacheKeyGenerator()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `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.
    `String` | `generateKey(org.apache.hc.core5.http.HttpHost host, org.apache.hc.core5.http.HttpRequest request, HttpCacheEntry entry)` Deprecated. Use `generateKey(HttpHost, HttpRequest)` or `generateVariantKey(HttpRequest, Collection)`
    `String` | `generateKey(URI requestUri)` Computes a key for the given request `URI` that can be used as a unique identifier for cached resources.
    `String` | `generateVariantKey(org.apache.hc.core5.http.HttpRequest request, Collection<String> variantNames)` Computes a "variant key" for the given request and the given variants.
    `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 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 URI` | `normalize(String requestUri)` Lenient URI parser that normalizes valid `URI`s and returns `null` for malformed URIs.
    `static URI` | `normalize(URI requestUri)` Returns normalized representation of the request URI optimized for use as a cache key.
    `static void` | `normalizeElements(Iterator<org.apache.hc.core5.http.Header> iterator, Consumer<String> consumer)`
    `static void` | `normalizeElements(org.apache.hc.core5.http.MessageHeaders message, String headerName, Consumer<String> consumer)`
    `String` | `resolve(URI uri)`
    `static List<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`

- - ### Field Detail

    - #### INSTANCE

          public static final CacheKeyGenerator INSTANCE

      Default instance of `CacheKeyGenerator`.

  - ### Constructor Detail

    - #### CacheKeyGenerator

          public CacheKeyGenerator()

  - ### Method Detail

    - #### resolve

          public String resolve(URI uri)

      Specified by:
        `resolve` in interface `org.apache.hc.core5.function.Resolver<URI,String>`

    - #### getRequestUri

          @Internal
          public static 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 URI normalize(URI requestUri)
                                         throws 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:
        `URISyntaxException`

    - #### normalize

          @Internal
          public static URI normalize(String requestUri)

      Lenient URI parser that normalizes valid `URI`s and returns `null` for malformed URIs.

    - #### generateKey

          public String generateKey(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 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 List<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,
                                                         String headerName,
                                                         Consumer<String> consumer)

    - #### normalizeElements

          @Internal
          public static void normalizeElements(Iterator<org.apache.hc.core5.http.Header> iterator,
                                                         Consumer<String> consumer)

    - #### generateVariantKey

          public String generateVariantKey(org.apache.hc.core5.http.HttpRequest request,
                                           Collection<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 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 String generateKey(org.apache.hc.core5.http.HttpHost host,
                                                org.apache.hc.core5.http.HttpRequest request,
                                                HttpCacheEntry entry)

      Deprecated. Use `generateKey(HttpHost, HttpRequest)` or `generateVariantKey(HttpRequest, Collection)`
      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

Copyright © 1999–2021 The Apache Software Foundation. All rights reserved.