Package io.deephaven.base.string.cache
Class ConcurrentBoundedStringCache<STRING_LIKE_TYPE extends CharSequence>
java.lang.Object
io.deephaven.base.string.cache.ConcurrentBoundedStringCache<STRING_LIKE_TYPE>
- All Implemented Interfaces:
StringCache<STRING_LIKE_TYPE>
public class ConcurrentBoundedStringCache<STRING_LIKE_TYPE extends CharSequence>
extends Object
implements StringCache<STRING_LIKE_TYPE>
This cache follows the same design as ConcurrentUnboundedStringCache, but uses a KeyedObjectCache (bounded,
concurrent-get, "pseudo-random pseudo-LRU" replacement) for its internal storage.
This implementation is thread-safe, and lock-free except for the insertion of new cached Strings on a cache miss.
-
Field Summary
Fields inherited from interface io.deephaven.base.string.cache.StringCache
CAPACITY_UNBOUNDED -
Constructor Summary
ConstructorsConstructorDescriptionConcurrentBoundedStringCache(StringCacheTypeAdapter<STRING_LIKE_TYPE> typeAdapter, int capacity, int collisionFactor) -
Method Summary
Modifier and TypeMethodDescriptionfinal intcapacity()Get a hint about this cache's capacity and behavior.final STRING_LIKE_TYPEgetCachedString(@NotNull StringCompatible protoString) final STRING_LIKE_TYPEgetCachedString(@NotNull String string) final STRING_LIKE_TYPEfinal @NotNull Class<STRING_LIKE_TYPE>getType()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.deephaven.base.string.cache.StringCache
getCachedString
-
Constructor Details
-
ConcurrentBoundedStringCache
public ConcurrentBoundedStringCache(StringCacheTypeAdapter<STRING_LIKE_TYPE> typeAdapter, int capacity, int collisionFactor) - Parameters:
typeAdapter- Adapter to make and compare cache members.capacity- Minimum capacity of the storage backing this cache.collisionFactor- Number of possible storage slots a given element might be stored in.
-
-
Method Details
-
capacity
public final int capacity()Description copied from interface:StringCacheGet a hint about this cache's capacity and behavior.- Specified by:
capacityin interfaceStringCache<STRING_LIKE_TYPE extends CharSequence>- Returns:
- -1 : This is an unbounded cache. 0 : This "cache" doesn't actually perform any caching. >0 : Actual capacity bound.
-
getType
- Specified by:
getTypein interfaceStringCache<STRING_LIKE_TYPE extends CharSequence>- Returns:
- The type of the elements in this cache.
-
getEmptyString
- Specified by:
getEmptyStringin interfaceStringCache<STRING_LIKE_TYPE extends CharSequence>- Returns:
- A cached STRING_LIKE_TYPE that represents the empty string.
-
getCachedString
@NotNull public final STRING_LIKE_TYPE getCachedString(@NotNull @NotNull StringCompatible protoString) - Specified by:
getCachedStringin interfaceStringCache<STRING_LIKE_TYPE extends CharSequence>- Parameters:
protoString- The string-like CharSequence to look up- Returns:
- A cached STRING_LIKE_TYPE that corresponds to the current value of the CharSequence expressed by protoString
-
getCachedString
- Specified by:
getCachedStringin interfaceStringCache<STRING_LIKE_TYPE extends CharSequence>- Parameters:
string- The String to look up- Returns:
- A cached STRING_LIKE_TYPE that corresponds to the CharSequence expressed by string
-