Top Description Inners Fields Constructors Methods
com.google.common.cache

public final Class CacheBuilderSpec

extends Object
Class Inheritance
Annotations
@SuppressWarnings:GoodTime
@GwtIncompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Strings.isNullOrEmpty

A specification of a CacheBuilder configuration.

CacheBuilderSpec supports parsing configuration off of a string, which makes it especially useful for command-line configuration of a CacheBuilder.

The string syntax is a series of comma-separated keys or key-value pairs, each corresponding to a CacheBuilder method.

The set of supported keys will grow as CacheBuilder evolves, but existing keys will never be removed.

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:

CacheBuilderSpec does not support configuring CacheBuilder methods with non-value parameters. These must be configured in code.

A new CacheBuilder can be instantiated from a CacheBuilderSpec using CacheBuilder#from(CacheBuilderSpec) or CacheBuilder#from(String).

Author
Adam Winer
Since
12.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class
pack-priv abstract static class
CacheBuilderSpec.DurationParser

Base class for parsing times with durations

pack-priv static class
pack-priv abstract static class
CacheBuilderSpec.IntegerParser

Base class for parsing integers.

pack-priv static class
pack-priv abstract static class
CacheBuilderSpec.LongParser

Base class for parsing integers.

pack-priv static class
pack-priv static class
pack-priv static class
pack-priv static class
private static interface
CacheBuilderSpec.ValueParser

Parses a single value.

pack-priv static class
CacheBuilderSpec.ValueStrengthParser

Parse weakValues and softValues

pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv long
pack-priv TimeUnit
pack-priv Integer
pack-priv Integer
private static final Splitter
KEY_VALUE_SPLITTER

Splits the key from the value.

private static final Splitter
KEYS_SPLITTER

Splits each key-value pair.

pack-priv LocalCache.Strength
pack-priv Long
pack-priv Long
pack-priv Boolean
pack-priv long
pack-priv TimeUnit
private final String
specification

Specification; used for toParseableString().

private static final ImmutableMap<String, CacheBuilderSpec.ValueParser>
VALUE_PARSERS

Map of names to ValueParser.

pack-priv LocalCache.Strength
pack-priv long
pack-priv TimeUnit

Constructor Summary

AccessConstructor and Description
private
CacheBuilderSpec(String specification)

Method Summary

Modifier and TypeMethod and Description
public static CacheBuilderSpec
disableCaching()

Returns a CacheBuilderSpec that will prevent caching.

private static Long
durationInNanos(long duration, TimeUnit unit)

Converts an expiration duration/unit pair into a single Long for hashing and equality.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
private static String
format(String format, Object... args)

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
public static CacheBuilderSpec
parse(String
the string form
cacheBuilderSpecification
)

Creates a CacheBuilderSpec from a string.

pack-priv CacheBuilder<Object, Object>
toCacheBuilder()

Returns a CacheBuilder configured according to this instance's specification.

public String
toParsableString()

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

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation for this CacheBuilderSpec instance.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

accessExpirationDurationback to summary
pack-priv long accessExpirationDuration
Annotations
@VisibleForTesting
accessExpirationTimeUnitback to summary
pack-priv TimeUnit accessExpirationTimeUnit
Annotations
@VisibleForTesting
@CheckForNull
concurrencyLevelback to summary
pack-priv Integer concurrencyLevel
Annotations
@VisibleForTesting
@CheckForNull
initialCapacityback to summary
pack-priv Integer initialCapacity
Annotations
@VisibleForTesting
@CheckForNull
KEY_VALUE_SPLITTERback to summary
private static final Splitter KEY_VALUE_SPLITTER

Splits the key from the value.

KEYS_SPLITTERback to summary
private static final Splitter KEYS_SPLITTER

Splits each key-value pair.

keyStrengthback to summary
pack-priv LocalCache.Strength keyStrength
Annotations
@VisibleForTesting
@CheckForNull
maximumSizeback to summary
pack-priv Long maximumSize
Annotations
@VisibleForTesting
@CheckForNull
maximumWeightback to summary
pack-priv Long maximumWeight
Annotations
@VisibleForTesting
@CheckForNull
recordStatsback to summary
pack-priv Boolean recordStats
Annotations
@VisibleForTesting
@CheckForNull
refreshDurationback to summary
pack-priv long refreshDuration
Annotations
@VisibleForTesting
refreshTimeUnitback to summary
pack-priv TimeUnit refreshTimeUnit
Annotations
@VisibleForTesting
@CheckForNull
specificationback to summary
private final String specification

Specification; used for toParseableString().

VALUE_PARSERSback to summary
private static final ImmutableMap<String, CacheBuilderSpec.ValueParser> VALUE_PARSERS

Map of names to ValueParser.

valueStrengthback to summary
pack-priv LocalCache.Strength valueStrength
Annotations
@VisibleForTesting
@CheckForNull
writeExpirationDurationback to summary
pack-priv long writeExpirationDuration
Annotations
@VisibleForTesting
writeExpirationTimeUnitback to summary
pack-priv TimeUnit writeExpirationTimeUnit
Annotations
@VisibleForTesting
@CheckForNull

Constructor Detail

CacheBuilderSpecback to summary
private CacheBuilderSpec(String specification)

Method Detail

disableCachingback to summary
public static CacheBuilderSpec disableCaching()

Returns a CacheBuilderSpec that will prevent caching.

durationInNanosback to summary
private static Long durationInNanos(long duration, TimeUnit unit)

Converts an expiration duration/unit pair into a single Long for hashing and equality. Uses nanos to match CacheBuilder implementation.

Annotations
@CheckForNull
equalsback to summary
public boolean equals(Object obj)

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
obj: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
formatback to summary
private static String format(String format, Object... args)
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this 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
parseback to summary
public static CacheBuilderSpec parse(String cacheBuilderSpecification)

Creates a CacheBuilderSpec from a string.

Parameters
cacheBuilderSpecification:String

the string form

toCacheBuilderback to summary
pack-priv CacheBuilder<Object, Object> toCacheBuilder()

Returns a CacheBuilder configured according to this instance's specification.

toParsableStringback to summary
public String toParsableString()

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

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation for this CacheBuilderSpec 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
com.google.common.cache back to summary

pack-priv Class CacheBuilderSpec.AccessDurationParser

extends DurationParser
Class Inheritance

Parse expireAfterAccess

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
Inherited from com.google.common.cache.CacheBuilderSpec.DurationParser:
parse

Constructor Detail

AccessDurationParserback to summary
pack-priv AccessDurationParser()

Method Detail

parseDurationback to summary
protected void parseDuration(CacheBuilderSpec spec, long duration, TimeUnit unit)

Implements abstract com.google.common.cache.CacheBuilderSpec.DurationParser.parseDuration.

Annotations
@Override
com.google.common.cache back to summary

pack-priv Class CacheBuilderSpec.ConcurrencyLevelParser

extends IntegerParser
Class Inheritance

Parse concurrencyLevel

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
Inherited from com.google.common.cache.CacheBuilderSpec.IntegerParser:
parse

Constructor Detail

ConcurrencyLevelParserback to summary
pack-priv ConcurrencyLevelParser()

Method Detail

parseIntegerback to summary
protected void parseInteger(CacheBuilderSpec spec, int value)

Implements abstract com.google.common.cache.CacheBuilderSpec.IntegerParser.parseInteger.

Annotations
@Override
com.google.common.cache back to summary

pack-priv abstract Class CacheBuilderSpec.DurationParser

extends Object
implements ValueParser
Class Inheritance
All Implemented Interfaces
com.google.common.cache.CacheBuilderSpec.ValueParser
Known Direct Subclasses
com.google.common.cache.CacheBuilderSpec.AccessDurationParser, com.google.common.cache.CacheBuilderSpec.WriteDurationParser, com.google.common.cache.CacheBuilderSpec.RefreshDurationParser

Base class for parsing times with durations

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
protected abstract void
parseDuration(CacheBuilderSpec spec, long duration, TimeUnit unit)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

DurationParserback to summary
pack-priv DurationParser()

Method Detail

parseback to summary
public void parse(CacheBuilderSpec spec, String key, String value)

Implements com.google.common.cache.CacheBuilderSpec.ValueParser.parse.

Annotations
@Override
parseDurationback to summary
protected abstract void parseDuration(CacheBuilderSpec spec, long duration, TimeUnit unit)
com.google.common.cache back to summary

pack-priv Class CacheBuilderSpec.InitialCapacityParser

extends IntegerParser
Class Inheritance

Parse initialCapacity

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
Inherited from com.google.common.cache.CacheBuilderSpec.IntegerParser:
parse

Constructor Detail

InitialCapacityParserback to summary
pack-priv InitialCapacityParser()

Method Detail

parseIntegerback to summary
protected void parseInteger(CacheBuilderSpec spec, int value)

Implements abstract com.google.common.cache.CacheBuilderSpec.IntegerParser.parseInteger.

Annotations
@Override
com.google.common.cache back to summary

pack-priv abstract Class CacheBuilderSpec.IntegerParser

extends Object
implements ValueParser
Class Inheritance
All Implemented Interfaces
com.google.common.cache.CacheBuilderSpec.ValueParser
Known Direct Subclasses
com.google.common.cache.CacheBuilderSpec.InitialCapacityParser, com.google.common.cache.CacheBuilderSpec.ConcurrencyLevelParser

Base class for parsing integers.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
protected abstract void
parseInteger(CacheBuilderSpec spec, int value)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

IntegerParserback to summary
pack-priv IntegerParser()

Method Detail

parseback to summary
public void parse(CacheBuilderSpec spec, String key, @Nullable String value)

Implements com.google.common.cache.CacheBuilderSpec.ValueParser.parse.

Annotations
@Override
parseIntegerback to summary
protected abstract void parseInteger(CacheBuilderSpec spec, int value)
com.google.common.cache back to summary

pack-priv Class CacheBuilderSpec.KeyStrengthParser

extends Object
implements ValueParser
Class Inheritance
All Implemented Interfaces
com.google.common.cache.CacheBuilderSpec.ValueParser

Parse weakKeys

Field Summary

Modifier and TypeField and Description
private final LocalCache.Strength

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

strengthback to summary
private final LocalCache.Strength strength

Constructor Detail

KeyStrengthParserback to summary
public KeyStrengthParser(LocalCache.Strength strength)

Method Detail

parseback to summary
public void parse(CacheBuilderSpec spec, String key, String value)

Implements com.google.common.cache.CacheBuilderSpec.ValueParser.parse.

Annotations
@Override
com.google.common.cache back to summary

pack-priv abstract Class CacheBuilderSpec.LongParser

extends Object
implements ValueParser
Class Inheritance
All Implemented Interfaces
com.google.common.cache.CacheBuilderSpec.ValueParser
Known Direct Subclasses
com.google.common.cache.CacheBuilderSpec.MaximumSizeParser, com.google.common.cache.CacheBuilderSpec.MaximumWeightParser

Base class for parsing integers.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
protected abstract void
parseLong(CacheBuilderSpec spec, long value)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

LongParserback to summary
pack-priv LongParser()

Method Detail

parseback to summary
public void parse(CacheBuilderSpec spec, String key, @Nullable String value)

Implements com.google.common.cache.CacheBuilderSpec.ValueParser.parse.

Annotations
@Override
parseLongback to summary
protected abstract void parseLong(CacheBuilderSpec spec, long value)
com.google.common.cache back to summary

pack-priv Class CacheBuilderSpec.MaximumSizeParser

extends LongParser
Class Inheritance

Parse maximumSize

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
Inherited from com.google.common.cache.CacheBuilderSpec.LongParser:
parse

Constructor Detail

MaximumSizeParserback to summary
pack-priv MaximumSizeParser()

Method Detail

parseLongback to summary
protected void parseLong(CacheBuilderSpec spec, long value)

Implements abstract com.google.common.cache.CacheBuilderSpec.LongParser.parseLong.

Annotations
@Override
com.google.common.cache back to summary

pack-priv Class CacheBuilderSpec.MaximumWeightParser

extends LongParser
Class Inheritance

Parse maximumWeight

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
Inherited from com.google.common.cache.CacheBuilderSpec.LongParser:
parse

Constructor Detail

MaximumWeightParserback to summary
pack-priv MaximumWeightParser()

Method Detail

parseLongback to summary
protected void parseLong(CacheBuilderSpec spec, long value)

Implements abstract com.google.common.cache.CacheBuilderSpec.LongParser.parseLong.

Annotations
@Override
com.google.common.cache back to summary

pack-priv Class CacheBuilderSpec.RecordStatsParser

extends Object
implements ValueParser
Class Inheritance
All Implemented Interfaces
com.google.common.cache.CacheBuilderSpec.ValueParser

Parse recordStats

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

RecordStatsParserback to summary
pack-priv RecordStatsParser()

Method Detail

parseback to summary
public void parse(CacheBuilderSpec spec, String key, String value)

Implements com.google.common.cache.CacheBuilderSpec.ValueParser.parse.

Annotations
@Override
com.google.common.cache back to summary

pack-priv Class CacheBuilderSpec.RefreshDurationParser

extends DurationParser
Class Inheritance

Parse refreshAfterWrite

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
Inherited from com.google.common.cache.CacheBuilderSpec.DurationParser:
parse

Constructor Detail

RefreshDurationParserback to summary
pack-priv RefreshDurationParser()

Method Detail

parseDurationback to summary
protected void parseDuration(CacheBuilderSpec spec, long duration, TimeUnit unit)

Implements abstract com.google.common.cache.CacheBuilderSpec.DurationParser.parseDuration.

Annotations
@Override
com.google.common.cache back to summary

private Interface CacheBuilderSpec.ValueParser

Known Direct Implementers
com.google.common.cache.CacheBuilderSpec.IntegerParser, com.google.common.cache.CacheBuilderSpec.LongParser, com.google.common.cache.CacheBuilderSpec.KeyStrengthParser, com.google.common.cache.CacheBuilderSpec.ValueStrengthParser, com.google.common.cache.CacheBuilderSpec.RecordStatsParser, com.google.common.cache.CacheBuilderSpec.DurationParser

Parses a single value.

Method Summary

Modifier and TypeMethod and Description
public void
parse(CacheBuilderSpec spec, String key, String value)

Method Detail

parseback to summary
public void parse(CacheBuilderSpec spec, String key, String value)
com.google.common.cache back to summary

pack-priv Class CacheBuilderSpec.ValueStrengthParser

extends Object
implements ValueParser
Class Inheritance
All Implemented Interfaces
com.google.common.cache.CacheBuilderSpec.ValueParser

Parse weakValues and softValues

Field Summary

Modifier and TypeField and Description
private final LocalCache.Strength

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

strengthback to summary
private final LocalCache.Strength strength

Constructor Detail

ValueStrengthParserback to summary
public ValueStrengthParser(LocalCache.Strength strength)

Method Detail

parseback to summary
public void parse(CacheBuilderSpec spec, String key, String value)

Implements com.google.common.cache.CacheBuilderSpec.ValueParser.parse.

Annotations
@Override
com.google.common.cache back to summary

pack-priv Class CacheBuilderSpec.WriteDurationParser

extends DurationParser
Class Inheritance

Parse expireAfterWrite

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
Inherited from com.google.common.cache.CacheBuilderSpec.DurationParser:
parse

Constructor Detail

WriteDurationParserback to summary
pack-priv WriteDurationParser()

Method Detail

parseDurationback to summary
protected void parseDuration(CacheBuilderSpec spec, long duration, TimeUnit unit)

Implements abstract com.google.common.cache.CacheBuilderSpec.DurationParser.parseDuration.

Annotations
@Override