- java.lang.Object
-
- com.github.benmanes.caffeine.cache.CaffeineSpec
-
public final class CaffeineSpec extends Object
A specification of aCaffeine
builder configuration.CaffeineSpec
supports parsing configuration off of a string, which makes it especially useful for command-line configuration of aCaffeine
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 configuringCaffeine
methods with non-value parameters. These must be configured in code.A new
Caffeine
builder can be instantiated from aCaffeineSpec
usingCaffeine.from(CaffeineSpec)
orCaffeine.from(String)
.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(@Nullable 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 equivalentCaffeineSpec
.String
toString()
Returns a string representation for thisCaffeineSpec
instance.
-
-
-
Method Detail
-
parse
public static CaffeineSpec parse(String specification)
Creates a CaffeineSpec from a string.- Parameters:
specification
- the string form- Returns:
- the parsed specification
-
toParsableString
public String 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
-
-