Class CaffeineSpec
- java.lang.Object
-
- com.github.benmanes.caffeine.cache.CaffeineSpec
-
public final class CaffeineSpec extends java.lang.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)
.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) @Nullable java.time.Duration
expireAfterAccess
(package private) @Nullable java.time.Duration
expireAfterWrite
(package private) int
initialCapacity
(package private) @Nullable Caffeine.Strength
keyStrength
(package private) long
maximumSize
(package private) long
maximumWeight
(package private) boolean
recordStats
(package private) @Nullable java.time.Duration
refreshAfterWrite
(package private) java.lang.String
specification
(package private) static java.lang.String
SPLIT_KEY_VALUE
(package private) static java.lang.String
SPLIT_OPTIONS
(package private) @Nullable Caffeine.Strength
valueStrength
-
Constructor Summary
Constructors Modifier Constructor Description private
CaffeineSpec(java.lang.String specification)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
configure(java.lang.String key, @Nullable java.lang.String value)
Configures the setting.boolean
equals(java.lang.Object o)
(package private) void
expireAfterAccess(java.lang.String key, @Nullable java.lang.String value)
Configures expire after access.(package private) void
expireAfterWrite(java.lang.String key, @Nullable java.lang.String value)
Configures expire after write.int
hashCode()
(package private) void
initialCapacity(java.lang.String key, @Nullable java.lang.String value)
Configures the initial capacity.(package private) void
maximumSize(java.lang.String key, @Nullable java.lang.String value)
Configures the maximum size.(package private) void
maximumWeight(java.lang.String key, @Nullable java.lang.String value)
Configures the maximum size.static @NonNull CaffeineSpec
parse(@NonNull java.lang.String specification)
Creates a CaffeineSpec from a string.(package private) static java.time.Duration
parseDuration(java.lang.String key, @Nullable java.lang.String value)
Returns a parsed duration value.(package private) static int
parseInt(java.lang.String key, @Nullable java.lang.String value)
Returns a parsed int value.(package private) static long
parseLong(java.lang.String key, @Nullable java.lang.String value)
Returns a parsed long value.(package private) void
parseOption(java.lang.String option)
Parses and applies the configuration option.(package private) static java.util.concurrent.TimeUnit
parseTimeUnit(java.lang.String key, @Nullable java.lang.String value)
Returns a parsedTimeUnit
value.(package private) void
recordStats(@Nullable java.lang.String value)
Configures the value as weak or soft references.(package private) void
refreshAfterWrite(java.lang.String key, @Nullable java.lang.String value)
Configures refresh after write.(package private) Caffeine<java.lang.Object,java.lang.Object>
toBuilder()
Returns aCaffeine
builder configured according to this specification.java.lang.String
toParsableString()
Returns a string that can be used to parse an equivalentCaffeineSpec
.java.lang.String
toString()
Returns a string representation for thisCaffeineSpec
instance.(package private) void
valueStrength(java.lang.String key, @Nullable java.lang.String value, Caffeine.Strength strength)
Configures the value as weak or soft references.(package private) void
weakKeys(@Nullable java.lang.String value)
Configures the keys as weak references.
-
-
-
Field Detail
-
SPLIT_OPTIONS
static final java.lang.String SPLIT_OPTIONS
- See Also:
- Constant Field Values
-
SPLIT_KEY_VALUE
static final java.lang.String SPLIT_KEY_VALUE
- See Also:
- Constant Field Values
-
specification
final java.lang.String 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 java.time.Duration expireAfterWrite
-
expireAfterAccess
@Nullable java.time.Duration expireAfterAccess
-
refreshAfterWrite
@Nullable java.time.Duration refreshAfterWrite
-
-
Method Detail
-
toBuilder
Caffeine<java.lang.Object,java.lang.Object> toBuilder()
Returns aCaffeine
builder configured according to this specification.- Returns:
- a builder configured to the specification
-
parse
public static @NonNull CaffeineSpec parse(@NonNull java.lang.String specification)
Creates a CaffeineSpec from a string.- Parameters:
specification
- the string form- Returns:
- the parsed specification
-
parseOption
void parseOption(java.lang.String option)
Parses and applies the configuration option.
-
configure
void configure(java.lang.String key, @Nullable java.lang.String value)
Configures the setting.
-
initialCapacity
void initialCapacity(java.lang.String key, @Nullable java.lang.String value)
Configures the initial capacity.
-
maximumSize
void maximumSize(java.lang.String key, @Nullable java.lang.String value)
Configures the maximum size.
-
maximumWeight
void maximumWeight(java.lang.String key, @Nullable java.lang.String value)
Configures the maximum size.
-
weakKeys
void weakKeys(@Nullable java.lang.String value)
Configures the keys as weak references.
-
valueStrength
void valueStrength(java.lang.String key, @Nullable java.lang.String value, Caffeine.Strength strength)
Configures the value as weak or soft references.
-
expireAfterAccess
void expireAfterAccess(java.lang.String key, @Nullable java.lang.String value)
Configures expire after access.
-
expireAfterWrite
void expireAfterWrite(java.lang.String key, @Nullable java.lang.String value)
Configures expire after write.
-
refreshAfterWrite
void refreshAfterWrite(java.lang.String key, @Nullable java.lang.String value)
Configures refresh after write.
-
recordStats
void recordStats(@Nullable java.lang.String value)
Configures the value as weak or soft references.
-
parseInt
static int parseInt(java.lang.String key, @Nullable java.lang.String value)
Returns a parsed int value.
-
parseLong
static long parseLong(java.lang.String key, @Nullable java.lang.String value)
Returns a parsed long value.
-
parseDuration
static java.time.Duration parseDuration(java.lang.String key, @Nullable java.lang.String value)
Returns a parsed duration value.
-
parseTimeUnit
static java.util.concurrent.TimeUnit parseTimeUnit(java.lang.String key, @Nullable java.lang.String value)
Returns a parsedTimeUnit
value.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toParsableString
public java.lang.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
-
toString
public java.lang.String toString()
Returns a string representation for thisCaffeineSpec
instance. The form of this representation is not guaranteed.- Overrides:
toString
in classjava.lang.Object
-
-