org.feijoas.mango.common.cache

LoadingCache

Related Docs: object LoadingCache | package cache

trait LoadingCache[K, V] extends Cache[K, V] with (K) ⇒ V

A semi-persistent mapping from keys to values. Values are automatically loaded by the cache, and are stored in the cache until either evicted or manually invalidated.

Implementations of this interface are expected to be thread-safe, and can be safely accessed by multiple concurrent threads.

When evaluated as a scala.Function, a cache yields the same result as invoking #getUnchecked.

Note that while this class is still annotated as Beta, the API is frozen from a consumer's standpoint. In other words existing methods are all considered non-Beta and won't be changed without going through an 18 month deprecation cycle; however new methods may be added at any time.

Annotations
@Beta()
Since

0.7 (copied from Guava-libraries)

Linear Supertypes
(K) ⇒ V, Cache[K, V], AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. LoadingCache
  2. Function1
  3. Cache
  4. AnyRef
  5. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def asMap(): Map[K, V]

    Returns a view of the entries stored in this cache as a thread-safe map.

    Returns a view of the entries stored in this cache as a thread-safe map. Modifications made to the map directly affect the cache.

    Definition Classes
    Cache
  2. abstract def get(key: K): Try[V]

    Returns the value associated with key in this cache, first loading that value if necessary.

    Returns the value associated with key in this cache, first loading that value if necessary. No observable state associated with this cache is modified until loading completes.

    If another call to #get or #getIfPresent is currently loading the value for key, simply waits for that thread to finish and returns its loaded value. Note that multiple threads can concurrently load values for distinct keys.

    Caches loaded by a CacheLoader will call CacheLoader#load to load new values into the cache. If another value was associated with key while the new value was loading then a removal notification will be sent for the new value.

    The CacheLoader should not throw exceptions. If the calculation from a CacheLoader can fail the use of CacheLoader[K,Option[V]] or CacheLoader[K,Try[V]] is preferred. If the cache loader associated with this cache is known not to throw checked exceptions, then prefer #getUnchecked over this method.

    Exceptions thrown

    ExecutionError if an error was thrown while loading the value

    ExecutionException if a checked exception was thrown while loading the value

    UncheckedExecutionException if an unchecked exception was thrown while loading the value

  3. abstract def getIfPresent(key: K): Option[V]

    Returns an Option which is Some(value) with the value associated with key in this cache, or None if there is no cached value for key.

    Returns an Option which is Some(value) with the value associated with key in this cache, or None if there is no cached value for key.

    Definition Classes
    Cache
  4. abstract def getOrElseUpdate(key: K, loader: () ⇒ V): V

    Returns the value associated with key in this cache, obtaining that value from loader if necessary.

    Returns the value associated with key in this cache, obtaining that value from loader if necessary. No observable state associated with this cache is modified until loading completes. This method provides a simple substitute for the conventional if cached, return; otherwise create, cache and return pattern.

    Warning: as with CacheLoader#load, loader must not return null; it may either return a non-null value or throw an exception. The recommend way would be to use a Cache[K, Option[V]] with loader return None instead of throwing an exception.

    This method is equivalent to Cache.get(K, Callable<? extends V>) from the Guava-Libraries.

    Definition Classes
    Cache
    Annotations
    @throws( ... )
    Exceptions thrown

    ExecutionError if an error was thrown while loading the value

    ExecutionException if a checked exception was thrown while loading the value

    UncheckedExecutionException if an unchecked exception was thrown while loading the value

  5. abstract def invalidate(key: K): Unit

    Discards any cached value for key key.

    Discards any cached value for key key.

    Definition Classes
    Cache
  6. abstract def invalidateAll(): Unit

    Discards all entries in the cache.

    Discards all entries in the cache.

    Definition Classes
    Cache
  7. abstract def put(key: K, value: V): Unit

    Adds a new key/value pair to this cache.

    Adds a new key/value pair to this cache. If the cache previously contained a value associated with the key, the old value is replaced by the value.

    Prefer getOrElseUpdate(key, loader) when using the conventional if cached, return; otherwise create, cache and return pattern.

    Definition Classes
    Cache
  8. abstract def refresh(key: K): Unit

    Loads a new value for key key, possibly asynchronously.

    Loads a new value for key key, possibly asynchronously. While the new value is loading the previous value (if any) will continue to be returned by get(key) unless it is evicted. If the new value is loaded successfully it will replace the previous value in the cache; if an exception is thrown while refreshing the previous value will remain, and the exception will be logged (using `java.util.logging.Logger`) and swallowed.

    Caches loaded by a CacheLoader will call CacheLoader#reload if the cache currently contains a value for key, and CacheLoader#load otherwise. Loading is asynchronous only if CacheLoader#reload was overridden with an asynchronous implementation.

    Returns without doing anything if another thread is currently loading the value for key. If the cache loader associated with this cache performs refresh asynchronously then this method may return before refresh completes.

  9. abstract def size(): Long

    Returns the approximate number of entries in this cache.

    Returns the approximate number of entries in this cache.

    Definition Classes
    Cache
  10. abstract def stats(): CacheStats

    Returns a current snapshot of this cache's cumulative statistics.

    Returns a current snapshot of this cache's cumulative statistics. All stats are initialized to zero, and are monotonically increasing over the lifetime of the cache.

    Definition Classes
    Cache

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  4. def andThen[A](g: (V) ⇒ A): (K) ⇒ A

    Definition Classes
    Function1
    Annotations
    @unspecialized()
  5. final def apply(keys: Traversable[K]): Map[K, V]

    Returns a map of the values associated with keys, creating or retrieving those values if necessary.

    Returns a map of the values associated with keys, creating or retrieving those values if necessary. The returned map contains entries that were already cached, combined with newly loaded entries; it will never contain null keys or values. The method simply forwards to getAll(keys).

  6. final def apply(key: K): V

    Returns the value associated with key in this cache, first loading that value if necessary.

    Returns the value associated with key in this cache, first loading that value if necessary. No observable state associated with this cache is modified until loading completes. The method simply forwards to get(key).

    Definition Classes
    LoadingCache → Function1
  7. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  8. def cleanUp(): Unit

    Performs any pending maintenance operations needed by the cache.

    Performs any pending maintenance operations needed by the cache. Exactly which activities are performed -- if any -- is implementation-dependent.

    Definition Classes
    Cache
  9. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. def compose[A](g: (A) ⇒ K): (A) ⇒ V

    Definition Classes
    Function1
    Annotations
    @unspecialized()
  11. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  12. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  13. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  14. def getAll(keys: Traversable[K]): Try[Map[K, V]]

    Returns a map of the values associated with keys, creating or retrieving those values if necessary.

    Returns a map of the values associated with keys, creating or retrieving those values if necessary. The returned map contains entries that were already cached, combined with newly loaded entries; it will never contain null keys or values.

    Caches loaded by a CacheLoader will issue a single request to CacheLoader#loadAll for all keys which are not already present in the cache. All entries returned by CacheLoader#loadAll will be stored in the cache, over-writing any previously cached values. This method will throw an exception if CacheLoader#loadAll returns null, returns a map containing null keys or values, or fails to return an entry for each requested key.

    Note that duplicate elements in keys, as determined by ==, will be ignored.

    Exceptions thrown

    ExecutionError if an error was thrown while loading the values

    ExecutionException if a checked exception was thrown while loading the values

    UncheckedExecutionException if an unchecked exception was thrown while loading the values

  15. def getAllPresent(keys: Traversable[K]): Map[K, V]

    Returns a map of the values associated with keys in this cache.

    Returns a map of the values associated with keys in this cache. The returned map will only contain entries which are already present in the cache.

    Definition Classes
    Cache
  16. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  17. def getUnchecked(key: K): V

    Returns the value associated with key in this cache, first loading that value if necessary.

    Returns the value associated with key in this cache, first loading that value if necessary. No observable state associated with this cache is modified until loading completes. Unlike #get, this method does not handle checked exceptions, and thus should only be used in situations where checked exceptions are not thrown by the cache loader.

    If another call to #get or #getUnchecked is currently loading the value for key, simply waits for that thread to finish and returns its loaded value. Note that multiple threads can concurrently load values for distinct keys.

    Caches loaded by a CacheLoader will call CacheLoader#load to load new values into the cache. Newly loaded values are added to the cache using Cache.asMap().putIfAbsent after loading has completed; if another value was associated with key while the new value was loading then a removal notification will be sent for the new value.

    Warning: this method silently converts checked exceptions to unchecked exceptions, and should not be used with cache loaders which throw checked exceptions. In such cases use #get instead.

    Exceptions thrown

    ExecutionError if an error was thrown while loading the value

    UncheckedExecutionException if an exception was thrown while loading the value, regardless of whether the exception was checked or unchecked

  18. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  19. def invalidateAll(keys: Traversable[K]): Unit

    Discards any cached values for keys keys.

    Discards any cached values for keys keys.

    Definition Classes
    Cache
  20. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  21. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  22. final def notify(): Unit

    Definition Classes
    AnyRef
  23. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  24. def putAll(kvs: Traversable[(K, V)]): Unit

    Puts all key/value pairs from the specified Traversable to the cache.

    Puts all key/value pairs from the specified Traversable to the cache. The effect of this call is equivalent to that of calling put(key, value) for each (key, value) in the Traversable. The behavior of this operation is undefined if the specified map is modified while the operation is in progress.

    Definition Classes
    Cache
  25. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  26. def toString(): String

    Definition Classes
    Function1 → AnyRef → Any
  27. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  28. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  29. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from (K) ⇒ V

Inherited from Cache[K, V]

Inherited from AnyRef

Inherited from Any

Ungrouped