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(java.time.Duration)
.expireAfterWrite=[duration]
: setsCaffeine.expireAfterWrite(java.time.Duration)
.refreshAfterWrite=[duration]
: setsCaffeine.refreshAfterWrite(java.time.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:
maximumSize
andmaximumWeight
weakValues
andsoftValues
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) void
Configures the setting.boolean
(package private) void
expireAfterAccess
(String key, @Nullable String value) Configures expire after access.(package private) void
expireAfterWrite
(String key, @Nullable String value) Configures expire after write.int
hashCode()
(package private) void
initialCapacity
(String key, @Nullable String value) Configures the initial capacity.(package private) void
maximumSize
(String key, @Nullable String value) Configures the maximum size.(package private) void
maximumWeight
(String key, @Nullable String value) Configures the maximum size.static @NonNull CaffeineSpec
Creates a CaffeineSpec from a string.(package private) static Duration
parseDuration
(String key, @Nullable String value) Returns a parsed duration value.(package private) static int
Returns a parsed int value.(package private) static long
Returns a parsed long value.(package private) void
parseOption
(String option) Parses and applies the configuration option.(package private) static TimeUnit
parseTimeUnit
(String key, @Nullable String value) Returns a parsedTimeUnit
value.(package private) void
recordStats
(@Nullable String value) Configures the value as weak or soft references.(package private) void
refreshAfterWrite
(String key, @Nullable String value) Configures refresh after write.Returns aCaffeine
builder configured according to this specification.Returns a string that can be used to parse an equivalentCaffeineSpec
.toString()
Returns a string representation for thisCaffeineSpec
instance.(package private) void
valueStrength
(String key, @Nullable String value, Caffeine.Strength strength) Configures the value as weak or soft references.(package private) void
Configures 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
Returns aCaffeine
builder configured according to this specification.- Returns:
- a builder configured to the specification
-
parse
Creates a CaffeineSpec from a string.- Parameters:
specification
- the string form- Returns:
- the parsed specification
-
parseOption
Parses and applies the configuration option. -
configure
Configures the setting. -
initialCapacity
Configures the initial capacity. -
maximumSize
Configures the maximum size. -
maximumWeight
Configures the maximum size. -
weakKeys
Configures the keys as weak references. -
valueStrength
Configures the value as weak or soft references. -
expireAfterAccess
Configures expire after access. -
expireAfterWrite
Configures expire after write. -
refreshAfterWrite
Configures refresh after write. -
recordStats
Configures the value as weak or soft references. -
parseInt
Returns a parsed int value. -
parseLong
Returns a parsed long value. -
parseDuration
Returns a parsed duration value. -
parseTimeUnit
Returns a parsedTimeUnit
value. -
equals
-
hashCode
public int 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 aCaffeineSpec
equal to this instance.- Returns:
- a string representation of this specification
-
toString
Returns a string representation for thisCaffeineSpec
instance. The form of this representation is not guaranteed.
-