Class CachedSharding<T extends Comparable<? super T>>

java.lang.Object
me.ahoo.cosid.sharding.CachedSharding<T>
Type Parameters:
T - the type of comparable sharding value
All Implemented Interfaces:
PreciseSharding<T>, RangeSharding<T>, Sharding<T>

public class CachedSharding<T extends Comparable<? super T>> extends Object implements Sharding<T>
Caching wrapper for sharding algorithms.

Caches range sharding results to reduce computation overhead for frequently accessed ranges. The cache is bounded: once it holds maximumSize ranges it is emptied before the next one is added, which keeps lookups lock-free (4.x used a Guava LRU cache).

A collection the range sharding returns is the cached one, shared by every later call for the same range: treat it as unmodifiable (R1-sharding-02). Changing it changes what the next calls return; a later version may return an unmodifiable view.

  • Field Details

    • DEFAULT_MAXIMUM_SIZE

      public static final long DEFAULT_MAXIMUM_SIZE
      The most ranges kept by default: query ranges come from user input, so the cache must not grow without bound.
      See Also:
  • Constructor Details

    • CachedSharding

      public CachedSharding(Sharding<T> actual)
      Creates a cached wrapper around the specified sharding algorithm.
      Parameters:
      actual - the underlying sharding algorithm
    • CachedSharding

      public CachedSharding(Sharding<T> actual, long maximumSize)
      Creates a cached wrapper around the specified sharding algorithm, keeping at most maximumSize ranges.
      Parameters:
      actual - the underlying sharding algorithm
      maximumSize - the most ranges kept in the cache
  • Method Details