Top Description Fields Constructors Methods
com.github.benmanes.caffeine.cache

public final Class CaffeineSpec

extends Object
Class Inheritance
Static Imports
com.github.benmanes.caffeine.cache.Caffeine.UNSET_INT, .Caffeine.requireArgument, .Caffeine.requireState, java.util.Locale.US, .Objects.requireNonNull

A specification of a Caffeine builder configuration.

CaffeineSpec supports parsing configuration from 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.

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:

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).

Author
[email protected] (Ben Manes)

Field Summary

Modifier and TypeField and Description
pack-priv @Nullable Duration
pack-priv @Nullable Duration
pack-priv int
pack-priv @Nullable Caffeine.Strength
pack-priv long
pack-priv long
pack-priv boolean
pack-priv @Nullable Duration
pack-priv final String
pack-priv static final String
pack-priv static final String
pack-priv @Nullable Caffeine.Strength

Constructor Summary

AccessConstructor and Description
private
CaffeineSpec(String specification)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
configure(String key, @Nullable String value)

Configures the setting.

public boolean
equals(@Nullable Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
pack-priv void
expireAfterAccess(String key, @Nullable String value)

Configures expire after access.

pack-priv void
expireAfterWrite(String key, @Nullable String value)

Configures expire after write.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
pack-priv void
initialCapacity(String key, @Nullable String value)

Configures the initial capacity.

pack-priv void
maximumSize(String key, @Nullable String value)

Configures the maximum size.

pack-priv void
maximumWeight(String key, @Nullable String value)

Configures the maximum size.

public static CaffeineSpec

Returns:

the parsed specification
parse
(String
the string form
specification
)

Creates a CaffeineSpec from a string.

pack-priv static Duration
parseDuration(String key, @Nullable String value)

Returns a parsed duration value.

pack-priv static int
parseInt(String key, @Nullable String value)

Returns a parsed int value.

pack-priv static long
parseLong(String key, @Nullable String value)

Returns a parsed long value.

pack-priv void
parseOption(String option)

Parses and applies the configuration option.

pack-priv static TimeUnit
parseTimeUnit(String key, @Nullable String value)

Returns a parsed TimeUnit value.

pack-priv void
recordStats(@Nullable String value)

Configures the value as weak or soft references.

pack-priv void
refreshAfterWrite(String key, @Nullable String value)

Configures refresh after write.

pack-priv Caffeine<Object, Object>

Returns:

a builder configured to the specification
toBuilder
()

Returns a Caffeine builder configured according to this specification.

public String

Returns:

a string representation of this specification that can be parsed into a CaffeineSpec
toParsableString
()

Returns a string representation that can be used to parse an equivalent CaffeineSpec.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation for this CaffeineSpec instance.
pack-priv void
valueStrength(String key, @Nullable String value, Caffeine.Strength strength)

Configures the value as weak or soft references.

pack-priv void
weakKeys(@Nullable String value)

Configures the keys as weak references.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

expireAfterAccessback to summary
pack-priv @Nullable Duration expireAfterAccess
expireAfterWriteback to summary
pack-priv @Nullable Duration expireAfterWrite
initialCapacityback to summary
pack-priv int initialCapacity
keyStrengthback to summary
pack-priv @Nullable Caffeine.Strength keyStrength
maximumSizeback to summary
pack-priv long maximumSize
maximumWeightback to summary
pack-priv long maximumWeight
recordStatsback to summary
pack-priv boolean recordStats
refreshAfterWriteback to summary
pack-priv @Nullable Duration refreshAfterWrite
specificationback to summary
pack-priv final String specification
SPLIT_KEY_VALUEback to summary
pack-priv static final String SPLIT_KEY_VALUE
SPLIT_OPTIONSback to summary
pack-priv static final String SPLIT_OPTIONS
valueStrengthback to summary
pack-priv @Nullable Caffeine.Strength valueStrength

Constructor Detail

CaffeineSpecback to summary
private CaffeineSpec(String specification)

Method Detail

configureback to summary
pack-priv void configure(String key, @Nullable String value)

Configures the setting.

equalsback to summary
public boolean equals(@Nullable Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:@Nullable Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
expireAfterAccessback to summary
pack-priv void expireAfterAccess(String key, @Nullable String value)

Configures expire after access.

expireAfterWriteback to summary
pack-priv void expireAfterWrite(String key, @Nullable String value)

Configures expire after write.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
initialCapacityback to summary
pack-priv void initialCapacity(String key, @Nullable String value)

Configures the initial capacity.

maximumSizeback to summary
pack-priv void maximumSize(String key, @Nullable String value)

Configures the maximum size.

maximumWeightback to summary
pack-priv void maximumWeight(String key, @Nullable String value)

Configures the maximum size.

parseback to summary
public static CaffeineSpec parse(String specification)

Creates a CaffeineSpec from a string.

Parameters
specification:String

the string form

Returns:CaffeineSpec

the parsed specification

Annotations
@SuppressWarnings:StringSplitter
parseDurationback to summary
pack-priv static Duration parseDuration(String key, @Nullable String value)

Returns a parsed duration value.

parseIntback to summary
pack-priv static int parseInt(String key, @Nullable String value)

Returns a parsed int value.

parseLongback to summary
pack-priv static long parseLong(String key, @Nullable String value)

Returns a parsed long value.

parseOptionback to summary
pack-priv void parseOption(String option)

Parses and applies the configuration option.

parseTimeUnitback to summary
pack-priv static TimeUnit parseTimeUnit(String key, @Nullable String value)

Returns a parsed TimeUnit value.

recordStatsback to summary
pack-priv void recordStats(@Nullable String value)

Configures the value as weak or soft references.

refreshAfterWriteback to summary
pack-priv void refreshAfterWrite(String key, @Nullable String value)

Configures refresh after write.

toBuilderback to summary
pack-priv Caffeine<Object, Object> toBuilder()

Returns a Caffeine builder configured according to this specification.

Returns:Caffeine<Object, Object>

a builder configured to the specification

toParsableStringback to summary
public String toParsableString()

Returns a string representation that can be used to parse an equivalent CaffeineSpec. The order and form of this representation is not guaranteed, except that parsing its output will produce a CaffeineSpec equal to this instance.

Returns:String

a string representation of this specification that can be parsed into a CaffeineSpec

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation for this CaffeineSpec instance. The form of this representation is not guaranteed.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override
valueStrengthback to summary
pack-priv void valueStrength(String key, @Nullable String value, Caffeine.Strength strength)

Configures the value as weak or soft references.

weakKeysback to summary
pack-priv void weakKeys(@Nullable String value)

Configures the keys as weak references.