Cache

sealed class Cache[R, Key, Value]
class Object
trait Matchable
class Any
class LoadingCache[R, Key, Value]

Value members

Concrete methods

Immediately run any pending maintenance operations on this cache, such as evicting expired entries.

Immediately run any pending maintenance operations on this cache, such as evicting expired entries.

Returns the estimated size for this cache. It is only an estimation as it depends if there are pending computations/evictions pending.

Returns the estimated size for this cache. It is only an estimation as it depends if there are pending computations/evictions pending.

Returns:

the estimated size of this cache

def get(key: Key)(mappingFunction: Key => RIO[R, Value]): Task[Value]

Returns the value associated to the given key in this cache, or asynchronously compute it if missing.

Returns the value associated to the given key in this cache, or asynchronously compute it if missing.

Value parameters:
key

the key whose associated value is to be returned

mappingFunction

the function defining how to compute a new value for a given key

Returns:

the current or newly computed value for the given key

def getAll(keys: Set[Key])(mappingFunction: Set[Key] => RIO[R, Map[Key, Value]]): Task[Map[Key, Value]]

Returns the values associated with the given keys in this cache, or asynchronously compute them if missing. Keys that are missing from the mappingFunction result won’t be saved in the cache.

Returns the values associated with the given keys in this cache, or asynchronously compute them if missing. Keys that are missing from the mappingFunction result won’t be saved in the cache.

Value parameters:
keys

the keys for which the associated values are to be returned

mappingFunction

the function defining how to compute values for keys that are missing from the cache

Returns:

the current or newly computed values for the given keys

def getAll(keys: Key*)(mappingFunction: Seq[Key] => RIO[R, Map[Key, Value]]): Task[Map[Key, Value]]

Returns the values associated with the given keys in this cache, or asynchronously compute them if missing. Keys that are missing from the mappingFunction result won’t be saved in the cache.

Returns the values associated with the given keys in this cache, or asynchronously compute them if missing. Keys that are missing from the mappingFunction result won’t be saved in the cache.

Value parameters:
keys

the keys for which the associated values are to be returned

mappingFunction

the function defining how to compute values for keys that are missing from the cache

Returns:

the current or newly computed values for the given keys

def getIfPresent(key: Key): Task[Option[Value]]

Returns the value associated with the given key if present in this cache, otherwise returns None.

Returns the value associated with the given key if present in this cache, otherwise returns None.

Value parameters:
key

the key whose associated value is to be returned

Returns:

the current value if present, otherwise None

def invalidate(key: Key): Task[Unit]

Removes the cached value for the given key in this cache if present.

Removes the cached value for the given key in this cache if present.

Value parameters:
key

the key whose cached value is to be removed from the cache

Removes all cached values in this cache.

Removes all cached values in this cache.

def invalidateAll(keys: Set[Key]): Task[Unit]

Remove the cached values for the given keys in this cache if present.

Remove the cached values for the given keys in this cache if present.

Value parameters:
keys

the keys whose cached values are to be removed from the cache

def invalidateAll(keys: Key*): Task[Unit]

Remove the cached values for the given keys in this cache if present.

Remove the cached values for the given keys in this cache if present.

Value parameters:
keys

the keys whose cached values are to be removed from the cache

def put(key: Key, value: RIO[R, Value]): RIO[R, Unit]

Creates or replaces the cached value for the given key in this cache. If the computation failed, remove the existing entry.

Creates or replaces the cached value for the given key in this cache. If the computation failed, remove the existing entry.

Value parameters:
key

the key to associate with the value

value

the value to associate with the key

Returns the cache statistics computed for this cache, if previously enabled with recordStats when building the cache. To be used with caution as it induces a performance penalty.

Returns the cache statistics computed for this cache, if previously enabled with recordStats when building the cache. To be used with caution as it induces a performance penalty.

Returns:

the cache statistics for this cache