Package org.apache.beam.fn.harness
Class Caches
- java.lang.Object
-
- org.apache.beam.fn.harness.Caches
-
public final class Caches extends java.lang.ObjectUtility methods used to instantiate and operate over cache instances.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCaches.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 longREFERENCE_SIZEThe 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 specifiedPipelineOptionsto configure and return a cache instance based upon parameters withinSdkHarnessOptions.static <K,V>
Cache<K,V>noop()A cache that never stores any values.static booleanshouldUpdateOnSizeChange(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 longweigh(java.lang.Object o)Returns the amount of memory in bytes the provided object consumes.
-
-
-
Field Detail
-
REFERENCE_SIZE
public static final long REFERENCE_SIZE
The size of a reference.- See Also:
- Constant Field Values
-
-
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 specifiedPipelineOptionsto configure and return a cache instance based upon parameters withinSdkHarnessOptions.
-
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
Cachewill be prefixed by the specified prefixes.
-
-