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(long, java.util.concurrent.TimeUnit)
.expireAfterWrite=[duration]
: setsCaffeine.expireAfterWrite(long, java.util.concurrent.TimeUnit)
.refreshAfterWrite=[duration]
: setsCaffeine.refreshAfterWrite(long, java.util.concurrent.TimeUnit)
.weakKeys
: setsCaffeine.weakKeys()
.weakValues
: setsCaffeine.weakValues()
.softValues
: setsCaffeine.softValues()
.recordStats
: setsCaffeine.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
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) long
(package private) TimeUnit
(package private) long
(package private) TimeUnit
(package private) int
(package private) Caffeine.Strength
(package private) long
(package private) long
(package private) boolean
(package private) long
(package private) TimeUnit
(package private) final String
(package private) static final String
(package private) static final String
(package private) Caffeine.Strength
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) void
Configures the setting.(package private) static long
durationInNanos
(long duration, TimeUnit unit) Converts an expiration duration/unit pair into a single long for hashing and equality.boolean
(package private) void
expireAfterAccess
(String key, String value) Configures expire after access.(package private) void
expireAfterWrite
(String key, String value) Configures expire after write.int
hashCode()
(package private) void
initialCapacity
(String key, String value) Configures the initial capacity.(package private) void
maximumSize
(String key, String value) Configures the maximum size.(package private) void
maximumWeight
(String key, String value) Configures the maximum size.static CaffeineSpec
Creates a CaffeineSpec from a string.(package private) static long
parseDuration
(String key, 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, String value) Returns a parsedTimeUnit
value.(package private) void
recordStats
(String value) Configures the value as weak or soft references.(package private) void
refreshAfterWrite
(String key, 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, 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
Caffeine.Strength keyStrength -
valueStrength
Caffeine.Strength valueStrength -
expireAfterAccessDuration
long expireAfterAccessDuration -
expireAfterAccessTimeUnit
TimeUnit expireAfterAccessTimeUnit -
expireAfterWriteDuration
long expireAfterWriteDuration -
expireAfterWriteTimeUnit
TimeUnit expireAfterWriteTimeUnit -
refreshAfterWriteDuration
long refreshAfterWriteDuration -
refreshAfterWriteTimeUnit
TimeUnit refreshAfterWriteTimeUnit
-
-
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() -
durationInNanos
Converts an expiration duration/unit pair into a single long for hashing and equality. -
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.
-