Class CacheBuilderSpec
- java.lang.Object
-
- com.google.common.cache.CacheBuilderSpec
-
@GwtIncompatible public final class CacheBuilderSpec extends java.lang.Object
A specification of aCacheBuilder
configuration.CacheBuilderSpec
supports parsing configuration off of a string, which makes it especially useful for command-line configuration of aCacheBuilder
.The string syntax is a series of comma-separated keys or key-value pairs, each corresponding to a
CacheBuilder
method.concurrencyLevel=[integer]
: setsCacheBuilder.concurrencyLevel
.initialCapacity=[integer]
: setsCacheBuilder.initialCapacity
.maximumSize=[long]
: setsCacheBuilder.maximumSize
.maximumWeight=[long]
: setsCacheBuilder.maximumWeight
.expireAfterAccess=[duration]
: setsCacheBuilder.expireAfterAccess(java.time.Duration)
.expireAfterWrite=[duration]
: setsCacheBuilder.expireAfterWrite(java.time.Duration)
.refreshAfterWrite=[duration]
: setsCacheBuilder.refreshAfterWrite(java.time.Duration)
.weakKeys
: setsCacheBuilder.weakKeys()
.softValues
: setsCacheBuilder.softValues()
.weakValues
: setsCacheBuilder.weakValues()
.recordStats
: setsCacheBuilder.recordStats()
.
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:
maximumSize
andmaximumWeight
softValues
andweakValues
CacheBuilderSpec
does not support configuringCacheBuilder
methods with non-value parameters. These must be configured in code.A new
CacheBuilder
can be instantiated from aCacheBuilderSpec
usingCacheBuilder.from(CacheBuilderSpec)
orCacheBuilder.from(String)
.- Since:
- 12.0
- Author:
- Adam Winer
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static CacheBuilderSpec
disableCaching()
Returns a CacheBuilderSpec that will prevent caching.boolean
equals(java.lang.Object obj)
int
hashCode()
static CacheBuilderSpec
parse(java.lang.String cacheBuilderSpecification)
Creates a CacheBuilderSpec from a string.java.lang.String
toParsableString()
Returns a string that can be used to parse an equivalentCacheBuilderSpec
.java.lang.String
toString()
Returns a string representation for this CacheBuilderSpec instance.
-
-
-
Method Detail
-
parse
public static CacheBuilderSpec parse(java.lang.String cacheBuilderSpecification)
Creates a CacheBuilderSpec from a string.- Parameters:
cacheBuilderSpecification
- the string form
-
disableCaching
public static CacheBuilderSpec disableCaching()
Returns a CacheBuilderSpec that will prevent caching.
-
toParsableString
public java.lang.String toParsableString()
Returns a string that can be used to parse an equivalentCacheBuilderSpec
. The order and form of this representation is not guaranteed, except that reparsing its output will produce aCacheBuilderSpec
equal to this instance.
-
toString
public java.lang.String toString()
Returns a string representation for this CacheBuilderSpec instance. The form of this representation is not guaranteed.- Overrides:
toString
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(@CheckForNull java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
-