Scaffeine

case class Scaffeine[K, V](underlying: Caffeine[K, V])
Companion:
object
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any

Value members

Concrete methods

def build[K1 <: K, V1 <: V](): Cache[K1, V1]

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

def build[K1 <: K, V1 <: V](loader: K1 => V1, allLoader: Option[Iterable[K1] => Map[K1, V1]], reloadLoader: Option[(K1, V1) => V1]): LoadingCache[K1, V1]

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

def buildAsync[K1 <: K, V1 <: V](): AsyncCache[K1, V1]

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

def buildAsync[K1 <: K, V1 <: V](loader: K1 => V1, allLoader: Option[Iterable[K1] => Map[K1, V1]], reloadLoader: Option[(K1, V1) => V1]): AsyncLoadingCache[K1, V1]

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

def buildAsyncFuture[K1 <: K, V1 <: V](loader: K1 => Future[V1], allLoader: Option[Iterable[K1] => Future[Map[K1, V1]]], reloadLoader: Option[(K1, V1) => Future[V1]]): AsyncLoadingCache[K1, V1]

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

def evictionListener[K1 <: K, V1 <: V](evictionListener: (K1, V1, RemovalCause) => Unit): Scaffeine[K1, V1]

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

def executor(executor: Executor): Scaffeine[K, V]

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

def expireAfter[K1 <: K, V1 <: V](create: (K1, V1) => FiniteDuration, update: (K1, V1, FiniteDuration) => FiniteDuration, read: (K1, V1, FiniteDuration) => FiniteDuration): Scaffeine[K1, V1]

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

def initialCapacity(initialCapacity: Int): Scaffeine[K, V]

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

def maximumSize(maximumSize: Long): Scaffeine[K, V]

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

def maximumWeight(maximumWeight: Long): Scaffeine[K, V]

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

def recordStats(): Scaffeine[K, V]

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

def recordStats[C <: StatsCounter](statsCounterSupplier: () => C): Scaffeine[K, V]

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

def removalListener[K1 <: K, V1 <: V](removalListener: (K1, V1, RemovalCause) => Unit): Scaffeine[K1, V1]

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

def scheduler(scheduler: Scheduler): Scaffeine[K, V]

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

def softValues(): Scaffeine[K, V]

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

def ticker(ticker: Ticker): Scaffeine[K, V]

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

def weakKeys(): Scaffeine[K, V]

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

def weakValues(): Scaffeine[K, V]

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

def weigher[K1 <: K, V1 <: V](weigher: (K1, V1) => Int): Scaffeine[K1, V1]

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

Inherited methods

Inherited from:
Product