Class CacheKeyBuilder

java.lang.Object
org.apache.druid.query.cache.CacheKeyBuilder

public class CacheKeyBuilder extends Object
CacheKeyBuilder is a tool for easily generating cache keys of Cacheable objects. The layout of the serialized cache key is like below. +--------------------------------------------------------+ | ID (1 byte) | | type key (1 byte) | serialized value (variable length) | | type key (1 byte) | serialized value (variable length) | | ... | +--------------------------------------------------------+
  • Constructor Details

    • CacheKeyBuilder

      public CacheKeyBuilder(byte id)
  • Method Details

    • appendByte

      public CacheKeyBuilder appendByte(byte input)
    • appendByteArray

      public CacheKeyBuilder appendByteArray(byte[] input)
    • appendString

      public CacheKeyBuilder appendString(@Nullable String input)
    • appendStrings

      public CacheKeyBuilder appendStrings(Collection<String> input)
      Add a collection of strings to the cache key. Strings in the collection are concatenated with a separator of '0xFF', and they appear in the cache key in their input order.
      Parameters:
      input - a collection of strings to be included in the cache key
      Returns:
      this instance
    • appendStringsIgnoringOrder

      public CacheKeyBuilder appendStringsIgnoringOrder(Collection<String> input)
      Add a collection of strings to the cache key. Strings in the collection are sorted by their byte representation and concatenated with a separator of '0xFF'.
      Parameters:
      input - a collection of strings to be included in the cache key
      Returns:
      this instance
    • appendBoolean

      public CacheKeyBuilder appendBoolean(boolean input)
    • appendInt

      public CacheKeyBuilder appendInt(int input)
    • appendLong

      public CacheKeyBuilder appendLong(long input)
    • appendFloat

      public CacheKeyBuilder appendFloat(float input)
    • appendDouble

      public CacheKeyBuilder appendDouble(double input)
    • appendDoubleArray

      public CacheKeyBuilder appendDoubleArray(double[] input)
    • appendFloatArray

      public CacheKeyBuilder appendFloatArray(float[] input)
    • appendCacheable

      public CacheKeyBuilder appendCacheable(@Nullable Cacheable input)
    • appendCacheables

      public CacheKeyBuilder appendCacheables(Collection<? extends Cacheable> input)
      Add a collection of Cacheables to the cache key. Cacheables in the collection are concatenated without any separator, and they appear in the cache key in their input order.
      Parameters:
      input - a collection of Cacheables to be included in the cache key
      Returns:
      this instance
    • appendCacheablesIgnoringOrder

      public CacheKeyBuilder appendCacheablesIgnoringOrder(Collection<? extends Cacheable> input)
      Add a collection of Cacheables to the cache key. Cacheables in the collection are sorted by their byte representation and concatenated without any separator.
      Parameters:
      input - a collection of Cacheables to be included in the cache key
      Returns:
      this instance
    • build

      @Nullable public byte[] build()