public final class CaffeineSpec extends Object
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]
: sets Caffeine.initialCapacity
.
maximumSize=[long]
: sets Caffeine.maximumSize
.
maximumWeight=[long]
: sets Caffeine.maximumWeight
.
expireAfterAccess=[duration]
: sets Caffeine.expireAfterAccess(java.time.Duration)
.
expireAfterWrite=[duration]
: sets Caffeine.expireAfterWrite(java.time.Duration)
.
refreshAfterWrite=[duration]
: sets Caffeine.refreshAfterWrite(java.time.Duration)
.
weakKeys
: sets Caffeine.weakKeys()
.
weakValues
: sets Caffeine.weakValues()
.
softValues
: sets Caffeine.softValues()
.
recordStats
: sets Caffeine.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
and maximumWeight
weakValues
and softValues
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)
.
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
int |
hashCode() |
static @NonNull CaffeineSpec |
parse(@NonNull String specification)
Creates a CaffeineSpec from a string.
|
String |
toParsableString()
Returns a string that can be used to parse an equivalent
CaffeineSpec . |
String |
toString()
Returns a string representation for this
CaffeineSpec instance. |
public static @NonNull CaffeineSpec parse(@NonNull String specification)
specification
- the string formpublic String toParsableString()
CaffeineSpec
. The order and
form of this representation is not guaranteed, except that parsing its output will produce a
CaffeineSpec
equal to this instance.