Class CacheBuilderSpec
CacheBuilder
configuration.
CacheBuilderSpec
supports parsing configuration off of a string, which makes it
especially useful for command-line configuration of a CacheBuilder
.
The string syntax is a series of comma-separated keys or key-value pairs, each corresponding
to a CacheBuilder
method.
concurrencyLevel=[integer]
: setsCacheBuilder.concurrencyLevel
.initialCapacity=[integer]
: setsCacheBuilder.initialCapacity
.maximumSize=[long]
: setsCacheBuilder.maximumSize
.maximumWeight=[long]
: setsCacheBuilder.maximumWeight
.expireAfterAccess=[duration]
: setsCacheBuilder.expireAfterAccess(java.time.Duration)
.expireAfterWrite=[duration]
: setsCacheBuilder.expireAfterWrite(java.time.Duration)
.refreshAfterWrite=[duration]
: setsCacheBuilder.refreshAfterWrite(java.time.Duration)
.weakKeys
: setsCacheBuilder.weakKeys()
.softValues
: setsCacheBuilder.softValues()
.weakValues
: setsCacheBuilder.weakValues()
.recordStats
: setsCacheBuilder.recordStats()
.
The set of supported keys will grow as CacheBuilder
evolves, but existing keys will
never be removed.
Durations are represented by an integer, followed by one of "d", "h", "m", or "s", representing days, hours, minutes, or seconds respectively. (There is currently no syntax to request expiration in milliseconds, microseconds, or nanoseconds.)
Whitespace before and after commas and equal signs is ignored. Keys may not be repeated; it is also illegal to use the following pairs of keys in a single value:
maximumSize
andmaximumWeight
softValues
andweakValues
CacheBuilderSpec
does not support configuring CacheBuilder
methods with
non-value parameters. These must be configured in code.
A new CacheBuilder
can be instantiated from a CacheBuilderSpec
using CacheBuilder.from(CacheBuilderSpec)
or CacheBuilder.from(String)
.
- Since:
- 12.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
Parse expireAfterAccess(package private) static class
Parse concurrencyLevel(package private) static class
Base class for parsing times with durations(package private) static class
Parse initialCapacity(package private) static class
Base class for parsing integers.(package private) static class
Parse weakKeys(package private) static class
Base class for parsing integers.(package private) static class
Parse maximumSize(package private) static class
Parse maximumWeight(package private) static class
Parse recordStats(package private) static class
Parse refreshAfterWriteprivate static interface
Parses a single value.(package private) static class
Parse weakValues and softValues(package private) static class
Parse expireAfterWrite -
Field Summary
FieldsModifier and TypeFieldDescription(package private) long
(package private) TimeUnit
(package private) Integer
(package private) Integer
private static final Splitter
Splits the key from the value.private static final Splitter
Splits each key-value pair.(package private) LocalCache.Strength
(package private) Long
(package private) Long
(package private) Boolean
(package private) long
(package private) TimeUnit
private final String
Specification; used for toParseableString().private static final ImmutableMap
<String, CacheBuilderSpec.ValueParser> Map of names to ValueParser.(package private) LocalCache.Strength
(package private) long
(package private) TimeUnit
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic CacheBuilderSpec
Returns a CacheBuilderSpec that will prevent caching.private static Long
durationInNanos
(long duration, TimeUnit unit) Converts an expiration duration/unit pair into a single Long for hashing and equality.boolean
private static String
int
hashCode()
static CacheBuilderSpec
Creates a CacheBuilderSpec from a string.(package private) CacheBuilder
<Object, Object> Returns a CacheBuilder configured according to this instance's specification.Returns a string that can be used to parse an equivalentCacheBuilderSpec
.toString()
Returns a string representation for this CacheBuilderSpec instance.
-
Field Details
-
KEYS_SPLITTER
Splits each key-value pair. -
KEY_VALUE_SPLITTER
Splits the key from the value. -
VALUE_PARSERS
Map of names to ValueParser. -
initialCapacity
-
maximumSize
-
maximumWeight
-
concurrencyLevel
-
keyStrength
-
valueStrength
-
recordStats
-
writeExpirationDuration
long writeExpirationDuration -
writeExpirationTimeUnit
-
accessExpirationDuration
long accessExpirationDuration -
accessExpirationTimeUnit
-
refreshDuration
long refreshDuration -
refreshTimeUnit
-
specification
Specification; used for toParseableString().
-
-
Constructor Details
-
CacheBuilderSpec
-
-
Method Details
-
parse
Creates a CacheBuilderSpec from a string.- Parameters:
cacheBuilderSpecification
- the string form
-
disableCaching
Returns a CacheBuilderSpec that will prevent caching. -
toCacheBuilder
CacheBuilder<Object,Object> toCacheBuilder()Returns a CacheBuilder configured according to this instance's specification. -
toParsableString
Returns a string that can be used to parse an equivalentCacheBuilderSpec
. The order and form of this representation is not guaranteed, except that reparsing its output will produce aCacheBuilderSpec
equal to this instance. -
toString
Returns a string representation for this CacheBuilderSpec instance. The form of this representation is not guaranteed. -
hashCode
public int hashCode() -
equals
-
durationInNanos
Converts an expiration duration/unit pair into a single Long for hashing and equality. Uses nanos to match CacheBuilder implementation. -
format
-