Class CaffeineSpec
Caffeine builder configuration.
CaffeineSpec supports parsing configuration off of a string, which makes it especially
useful for command-line configuration of a Caffeine builder.
The string syntax is a series of comma-separated keys or key-value pairs, each corresponding to a
Caffeine builder method.
initialCapacity=[integer]: setsCaffeine.initialCapacity.maximumSize=[long]: setsCaffeine.maximumSize.maximumWeight=[long]: setsCaffeine.maximumWeight.expireAfterAccess=[duration]: setsCaffeine.expireAfterAccess(Duration).expireAfterWrite=[duration]: setsCaffeine.expireAfterWrite(Duration).refreshAfterWrite=[duration]: setsCaffeine.refreshAfterWrite(Duration).weakKeys: setsCaffeine.weakKeys().weakValues: setsCaffeine.weakValues().softValues: setsCaffeine.softValues().recordStats: setsCaffeine.recordStats().
Durations are represented as either an ISO-8601 string using Duration.parse(CharSequence)
or by an integer followed by one of "d", "h", "m", or "s", representing days, hours, minutes, or
seconds respectively. There is currently no short syntax to request durations 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:
maximumSizeandmaximumWeightweakValuesandsoftValues
CaffeineSpec does not support configuring Caffeine methods with non-value
parameters. These must be configured in code.
A new Caffeine builder can be instantiated from a CaffeineSpec using
Caffeine.from(CaffeineSpec) or Caffeine.from(String).
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) @Nullable Duration(package private) @Nullable Duration(package private) int(package private) @Nullable Caffeine.Strength(package private) long(package private) long(package private) boolean(package private) @Nullable Duration(package private) final String(package private) static final String(package private) static final String(package private) @Nullable Caffeine.Strength -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidConfigures the setting.boolean(package private) voidexpireAfterAccess(String key, @Nullable String value) Configures expire after access.(package private) voidexpireAfterWrite(String key, @Nullable String value) Configures expire after write.inthashCode()(package private) voidinitialCapacity(String key, @Nullable String value) Configures the initial capacity.(package private) voidmaximumSize(String key, @Nullable String value) Configures the maximum size.(package private) voidmaximumWeight(String key, @Nullable String value) Configures the maximum size.static @NonNull CaffeineSpecCreates a CaffeineSpec from a string.(package private) static DurationparseDuration(String key, @Nullable String value) Returns a parsed duration value.(package private) static intReturns a parsed int value.(package private) static longReturns a parsed long value.(package private) voidparseOption(String option) Parses and applies the configuration option.(package private) static TimeUnitparseTimeUnit(String key, @Nullable String value) Returns a parsedTimeUnitvalue.(package private) voidrecordStats(@Nullable String value) Configures the value as weak or soft references.(package private) voidrefreshAfterWrite(String key, @Nullable String value) Configures refresh after write.Returns aCaffeinebuilder configured according to this specification.Returns a string that can be used to parse an equivalentCaffeineSpec.toString()Returns a string representation for thisCaffeineSpecinstance.(package private) voidvalueStrength(String key, @Nullable String value, Caffeine.Strength strength) Configures the value as weak or soft references.(package private) voidConfigures the keys as weak references.
-
Field Details
-
SPLIT_OPTIONS
- See Also:
-
SPLIT_KEY_VALUE
- See Also:
-
specification
-
initialCapacity
int initialCapacity -
maximumWeight
long maximumWeight -
maximumSize
long maximumSize -
recordStats
boolean recordStats -
keyStrength
@Nullable Caffeine.Strength keyStrength -
valueStrength
@Nullable Caffeine.Strength valueStrength -
expireAfterWrite
@Nullable Duration expireAfterWrite -
expireAfterAccess
@Nullable Duration expireAfterAccess -
refreshAfterWrite
@Nullable Duration refreshAfterWrite
-
-
Constructor Details
-
CaffeineSpec
-
-
Method Details
-
toBuilder
-
parse
Creates a CaffeineSpec from a string.- Parameters:
specification- the string form- Returns:
- the parsed specification
-
parseOption
Parses and applies the configuration option. -
configure
-
initialCapacity
-
maximumSize
-
maximumWeight
-
weakKeys
Configures the keys as weak references. -
valueStrength
Configures the value as weak or soft references. -
expireAfterAccess
-
expireAfterWrite
-
refreshAfterWrite
-
recordStats
Configures the value as weak or soft references. -
parseInt
-
parseLong
-
parseDuration
-
parseTimeUnit
-
equals
-
hashCode
-
toParsableString
Returns a string that can be used to parse an equivalentCaffeineSpec. The order and form of this representation is not guaranteed, except that parsing its output will produce aCaffeineSpecequal to this instance.- Returns:
- a string representation of this specification
-
toString
-