- Companion:
- object
Value members
Concrete methods
Builds a cache which does not automatically load values when keys are requested.
Builds a cache which does not automatically load values when keys are requested.
- Type parameters:
- K1
the key type of the cache
- V1
the value type of the cache
- Returns:
a cache having the requested features
Builds a cache, which either returns an already-loaded value for a given
key or atomically computes or retrieves it using the supplied loader
. If
another thread is currently loading the value for this key, simply waits
for that thread to finish and returns its loaded value. Note that multiple
threads can concurrently load values for distinct keys.
Builds a cache, which either returns an already-loaded value for a given
key or atomically computes or retrieves it using the supplied loader
. If
another thread is currently loading the value for this key, simply waits
for that thread to finish and returns its loaded value. Note that multiple
threads can concurrently load values for distinct keys.
- Type parameters:
- K1
the key type of the loader
- V1
the value type of the loader
- Value parameters:
- allLoader
the loader used to obtain new values in bulk, called by LoadingCache.getAll
- loader
the loader used to obtain new values
- reloadLoader
the loader used to obtain already-cached values
- Returns:
a cache having the requested features
Builds a cache which does not automatically load values when keys are requested unless a mapping function is provided. The returned scala.concurrent.Future may be already loaded or currently computing the value for a given key. If the asynchronous computation fails value then the entry will be automatically removed. Note that multiple threads can concurrently load values for distinct keys.
Builds a cache which does not automatically load values when keys are requested unless a mapping function is provided. The returned scala.concurrent.Future may be already loaded or currently computing the value for a given key. If the asynchronous computation fails value then the entry will be automatically removed. Note that multiple threads can concurrently load values for distinct keys.
- Type parameters:
- K1
the key type of the cache
- V1
the value type of the cache
- Returns:
a cache having the requested features
Builds a cache, which either returns a scala.concurrent.Future already
loaded or currently computing the value for a given key, or atomically
computes the value asynchronously through a supplied mapping function or
the supplied loader
. If the asynchronous computation fails then the
entry will be automatically removed. Note that multiple threads can
concurrently load values for distinct keys.
Builds a cache, which either returns a scala.concurrent.Future already
loaded or currently computing the value for a given key, or atomically
computes the value asynchronously through a supplied mapping function or
the supplied loader
. If the asynchronous computation fails then the
entry will be automatically removed. Note that multiple threads can
concurrently load values for distinct keys.
- Type parameters:
- K1
the key type of the loader
- V1
the value type of the loader
- Value parameters:
- allLoader
the loader used to obtain new values in bulk, called by AsyncLoadingCache.getAll
- loader
the loader used to obtain new values
- reloadLoader
the loader used to obtain already-cached values
- Returns:
a cache having the requested features
- Throws:
- java.lang.IllegalStateException
if the value strength is weak or soft
Builds a cache, which either returns a scala.concurrent.Future already
loaded or currently computing the value for a given key, or atomically
computes the value asynchronously through a supplied mapping function or
the supplied async loader
. If the asynchronous computation fails then
the entry will be automatically removed. Note that multiple threads can
concurrently load values for distinct keys.
Builds a cache, which either returns a scala.concurrent.Future already
loaded or currently computing the value for a given key, or atomically
computes the value asynchronously through a supplied mapping function or
the supplied async loader
. If the asynchronous computation fails then
the entry will be automatically removed. Note that multiple threads can
concurrently load values for distinct keys.
- Type parameters:
- K1
the key type of the loader
- V1
the value type of the loader
- Value parameters:
- allLoader
the loader used to obtain new values in bulk, called by AsyncLoadingCache.getAll
- loader
the loader used to obtain new values
- reloadLoader
the loader used to obtain already-cached values
- Throws:
- java.lang.IllegalStateException
if the value strength is weak or soft
Specifies a listener instance that caches should notify each time an entry is evicted.
Specifies a listener instance that caches should notify each time an entry is evicted.
- Type parameters:
- K1
the key type of the listener
- V1
the value type of the listener
- Value parameters:
- evictionListener
a listener that caches should notify each time an entry is being automatically removed due to eviction
- Returns:
this builder instance
- Throws:
- java.lang.IllegalStateException
if a removal listener was already set
Specifies the executor to use when running asynchronous tasks.
Specifies the executor to use when running asynchronous tasks.
- Value parameters:
- executor
the executor to use for asynchronous execution
- Returns:
this builder instance
Specifies that each entry should be automatically removed from the cache once a duration has elapsed after the entry's creation, the most recent replacement of its value, or its last read.
Specifies that each entry should be automatically removed from the cache once a duration has elapsed after the entry's creation, the most recent replacement of its value, or its last read.
- Type parameters:
- K1
the key type of the expiry.
- V1
the value type of the expiry.
- Value parameters:
- create
the length of time an entry should be automatically removed from the cache after the entry's creation.
- read
the length of time an entry should be automatically removed from the cache after the entry's last read.
- update
the length of time an entry should be automatically removed from the cache after the replacement of it's value.
- Returns:
this builder instance
- Throws:
- java.lang.IllegalStateException
if expiration was already set or used with expiresAfterAccess or expiresAfterWrite.
Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after the entry's creation, the most recent replacement of its value, or its last read.
Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after the entry's creation, the most recent replacement of its value, or its last read.
- Value parameters:
- duration
the length of time after an entry is last accessed that it should be automatically removed
- Returns:
this builder instance
- Throws:
- java.lang.IllegalArgumentException
if
duration
is negative- java.lang.IllegalStateException
if the time to idle or time to live was already set
Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after the entry's creation, or the most recent replacement of its value.
Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after the entry's creation, or the most recent replacement of its value.
- Value parameters:
- duration
the length of time after an entry is created that it should be automatically removed
- Returns:
this builder instance
- Throws:
- java.lang.IllegalArgumentException
if
duration
is negative- java.lang.IllegalStateException
if the time to live or time to idle was already set
Sets the minimum total size for the internal hash tables.
Sets the minimum total size for the internal hash tables.
- Value parameters:
- initialCapacity
minimum total size for the internal hash tables
- Returns:
this builder instance
- Throws:
- java.lang.IllegalArgumentException
if initialCapacity
- java.lang.IllegalStateException
if an initial capacity was already set
Specifies the maximum number of entries the cache may contain.
Specifies the maximum number of entries the cache may contain.
- Value parameters:
- maximumSize
the maximum size of the cache
- Returns:
this builder instance
- Throws:
- java.lang.IllegalArgumentException
size
is negative- java.lang.IllegalStateException
if a maximum size or weight was already set
Specifies the maximum weight of entries the cache may contain.
Specifies the maximum weight of entries the cache may contain.
This feature cannot be used in conjunction with Scaffeine.maximumSize.
- Value parameters:
- maximumWeight
the maximum total weight of entries the cache may contain
- Returns:
this builder instance
- Throws:
- java.lang.IllegalArgumentException
if
maximumWeight
is negative- java.lang.IllegalStateException
if a maximum weight or size was already set
Enables the accumulation of com.github.benmanes.caffeine.cache.stats.CacheStats during the operation of the cache.
Enables the accumulation of com.github.benmanes.caffeine.cache.stats.CacheStats during the operation of the cache.
- Returns:
this builder instance
Enables the accumulation of com.github.benmanes.caffeine.cache.stats.CacheStats during the operation of the cache.
Enables the accumulation of com.github.benmanes.caffeine.cache.stats.CacheStats during the operation of the cache.
- Value parameters:
- statsCounterSupplier
a supplier that returns a new com.github.benmanes.caffeine.cache.stats.StatsCounter
- Returns:
this builder instance
Specifies that active entries are eligible for automatic refresh once a fixed duration has elapsed after the entry's creation, or the most recent replacement of its value.
Specifies that active entries are eligible for automatic refresh once a fixed duration has elapsed after the entry's creation, or the most recent replacement of its value.
- Value parameters:
- duration
the length of time after an entry is created that it should be considered stale, and thus eligible for refresh
- Returns:
this builder instance
- Throws:
- java.lang.IllegalArgumentException
if
duration
is negative- java.lang.IllegalStateException
if the refresh interval was already set
Specifies a listener instance that caches should notify each time an entry is removed for any com.github.benmanes.caffeine.cache.RemovalCause.
Specifies a listener instance that caches should notify each time an entry is removed for any com.github.benmanes.caffeine.cache.RemovalCause.
- Type parameters:
- K1
the key type of the listener
- V1
the value type of the listener
- Value parameters:
- removalListener
a listener that caches should notify each time an entry is removed
- Returns:
this builder instance
- Throws:
- java.lang.IllegalStateException
if a removal listener was already set
Specifies the scheduler to use when scheduling routine maintenance based on an expiration event. This augments the periodic maintenance that occurs during normal cache operations to allow for the prompt removal of expired entries regardless of whether any cache activity is occurring at that time. By default the scheduler is disabled.
Specifies the scheduler to use when scheduling routine maintenance based on an expiration event. This augments the periodic maintenance that occurs during normal cache operations to allow for the prompt removal of expired entries regardless of whether any cache activity is occurring at that time. By default the scheduler is disabled.
- Value parameters:
- scheduler
the scheduler that submits a task to the Scaffeine.executor* after a given delay
- Returns:
this builder instance
Specifies that each value (not key) stored in the cache should be wrapped in a java.lang.ref.SoftReference (by default, strong references are used).
Specifies that each value (not key) stored in the cache should be wrapped in a java.lang.ref.SoftReference (by default, strong references are used).
This feature cannot be used in conjunction with [[Scaffeine.buildAsyncK1<:K,V1<:V*]].
- Returns:
this builder instance
- Throws:
- java.lang.IllegalStateException
if the value strength was already set
Specifies a nanosecond-precision time source for use in determining when
entries should be expired or refreshed. By default,
java.lang.System.nanoTime
is used.
Specifies a nanosecond-precision time source for use in determining when
entries should be expired or refreshed. By default,
java.lang.System.nanoTime
is used.
- Value parameters:
- ticker
a nanosecond-precision time source
- Returns:
this builder instance
- Throws:
- java.lang.IllegalStateException
if a ticker was already set
Specifies that each key (not value) stored in the cache should be wrapped in a java.lang.ref.WeakReference (by default, strong references are used).
Specifies that each key (not value) stored in the cache should be wrapped in a java.lang.ref.WeakReference (by default, strong references are used).
- Returns:
this builder instance
- Throws:
- java.lang.IllegalStateException
if the key strength was already set or the writer was set
Specifies that each value (not key) stored in the cache should be wrapped in a java.lang.ref.WeakReference (by default, strong references are used).
Specifies that each value (not key) stored in the cache should be wrapped in a java.lang.ref.WeakReference (by default, strong references are used).
This feature cannot be used in conjunction with [[Scaffeine.buildAsyncK1<:K,V1<:V*]].
- Returns:
this builder instance
- Throws:
- java.lang.IllegalStateException
if the value strength was already set
Specifies the weigher to use in determining the weight of entries.
Specifies the weigher to use in determining the weight of entries.
- Type parameters:
- K1
key type of the weigher
- V1
value type of the weigher
- Value parameters:
- weigher
the weigher to use in calculating the weight of cache entries
- Returns:
this builder instance
- Throws:
- java.lang.IllegalArgumentException
if
size
is negative- java.lang.IllegalStateException
if a maximum size was already set