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(long, java.util.concurrent.TimeUnit)
.
expireAfterWrite=[duration]
: sets Caffeine.expireAfterWrite(long, java.util.concurrent.TimeUnit)
.
refreshAfterWrite=[duration]
: sets Caffeine.refreshAfterWrite(long, java.util.concurrent.TimeUnit)
.
weakKeys
: sets Caffeine.weakKeys()
.
weakValues
: sets Caffeine.weakValues()
.
softValues
: sets Caffeine.softValues()
.
recordStats
: sets Caffeine.recordStats()
.
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
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 CaffeineSpec |
parse(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 CaffeineSpec parse(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.