Class Caches


  • public final class Caches
    extends java.lang.Object
    Utility methods used to instantiate and operate over cache instances.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Caches.ClearableCache<K,​V>
      A cache that tracks keys that have been inserted into the cache and supports clearing them.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static long REFERENCE_SIZE
      The size of a reference.
    • Constructor Summary

      Constructors 
      Constructor Description
      Caches()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <K,​V>
      Cache<K,​V>
      eternal()
      A cache that never evicts any values.
      static <K,​V>
      Cache<K,​V>
      fromOptions​(org.apache.beam.sdk.options.PipelineOptions options)
      Uses the specified PipelineOptions to configure and return a cache instance based upon parameters within SdkHarnessOptions.
      static <K,​V>
      Cache<K,​V>
      noop()
      A cache that never stores any values.
      static boolean shouldUpdateOnSizeChange​(long oldSize, long newSize)
      Returns whether the cache should be updated in the case where the objects size has changed.
      static <K,​V>
      Cache<K,​V>
      subCache​(Cache<?,​?> cache, java.lang.Object keyPrefix, java.lang.Object... additionalKeyPrefix)
      Returns a view of a cache that operates on keys with a specified key prefix.
      static long weigh​(java.lang.Object o)
      Returns the amount of memory in bytes the provided object consumes.
      • Methods inherited from class java.lang.Object

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

      • REFERENCE_SIZE

        public static final long REFERENCE_SIZE
        The size of a reference.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Caches

        public Caches()
    • Method Detail

      • weigh

        public static long weigh​(java.lang.Object o)
        Returns the amount of memory in bytes the provided object consumes.
      • shouldUpdateOnSizeChange

        public static boolean shouldUpdateOnSizeChange​(long oldSize,
                                                       long newSize)
        Returns whether the cache should be updated in the case where the objects size has changed.

        Note that this should only be used in the case where the cache is being updated very often in a tight loop and is not a good fit for cases where the object being cached is the result of an expensive operation like a disk read or remote service call.

      • noop

        public static <K,​V> Cache<K,​V> noop()
        A cache that never stores any values.
      • eternal

        public static <K,​V> Cache<K,​V> eternal()
        A cache that never evicts any values.
      • fromOptions

        public static <K,​V> Cache<K,​V> fromOptions​(org.apache.beam.sdk.options.PipelineOptions options)
        Uses the specified PipelineOptions to configure and return a cache instance based upon parameters within SdkHarnessOptions.
      • subCache

        public static <K,​V> Cache<K,​V> subCache​(Cache<?,​?> cache,
                                                            java.lang.Object keyPrefix,
                                                            java.lang.Object... additionalKeyPrefix)
        Returns a view of a cache that operates on keys with a specified key prefix.

        All lookups, insertions, and removals into the parent Cache will be prefixed by the specified prefixes.