A semi-persistent mapping from keys to values.
A semi-persistent mapping from keys to values. Cache entries are manually added using
getOrElseUpdate(key, loader)
or put(key, value)
, 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.
0.7 (copied from Guava-libraries)
A builder of LoadingCache and Cache instances having any combination of the following features:
A builder of LoadingCache and Cache instances having any combination of the following features:
These features are all optional; caches can be created using all or none of them. By default
cache instances created by CacheBuilder
will not perform any type of eviction.
Usage example:
val createExpensiveGraph: Key => Graph = ... val graphs: LoadingCache[Key, Graph] = CacheBuilder.newBuilder() .maximumSize(10000) .expireAfterWrite(10, TimeUnit.MINUTES) .removalListener(MY_LISTENER) .build(createExpensiveGraph)
This class just delegates to the CacheBuilder implementation in Guava
Note: by default, the returned cache uses equality comparisons to determine
equality for keys or values. However, if weakKeys
was specified, the cache uses identity (eq
)
comparisons instead for keys. Likewise, if weakValues
or softValues
was
specified, the cache uses identity comparisons for values.
Entries are automatically evicted from the cache when any of
maximumSize(Long)
maximumWeight(Long)
expireAfterWrite
expireAfterAccess
weakKeys
weakValues
softValues
are requested.
If maximumSize
or maximumWeight
is requested entries may be evicted on each cache
modification.
If expireAfterWrite
or #expireAfterAccess
is requested entries may be evicted on each
cache modification, on occasional cache accesses, or on calls to Cache.cleanUp()
. Expired
entries may be counted in Cache.size()
}, but will never be visible to read or write
operations.
If weakKeys
, weakValues
, or softValues
are requested, it is possible for a key or value present in
the cache to be reclaimed by the garbage collector. Entries with reclaimed keys or values may be
removed from the cache on each cache modification, on occasional cache accesses, or on calls to
Cache.cleanUp()
; such entries may be counted in Cache.size()
, but will never be
visible to read or write operations.
Certain cache configurations will result in the accrual of periodic maintenance tasks which
will be performed during write operations, or during occasional read operations in the absense of
writes. The Cache.cleanUp()
method of the returned cache will also perform maintenance, but
calling it should not be necessary with a high throughput cache. Only caches built with
removalListener
, expireAfterWrite
, expireAfterAccess
, weakKeys
, weakValues
, or
softValues
perform periodic maintenance.
The caches produced by CacheBuilder are serializable, and the deserialized caches retain all the configuration properties of the original cache. Note that the serialized form does not include cache contents, but only configuration.
Warning: This implementation differs from Guava. It is truly immutable and returns a new
instance on each method call. Use the standard method-chaining idiom,
as illustrated in the documentation above. This has the advantage that it is
not possible to create a cache whose key or value type is incompatible with e.g. the weigher. This
CacheBuilder
is also contravariant in both type K
and V
.
See the Guava User Guide for more information.
the key of the cache
the value of the cache
0.7 (copied from Guava-libraries)
Computes or retrieves values, based on a key, for use in populating a LoadingCache.
Computes or retrieves values, based on a key, for use in populating a LoadingCache.
This class should be when bulk retrieval is significantly more efficient than
many individual lookups. Otherwise the CacheLoader
companion object can be used
to create a CacheLoader[K,V]
from a function K => V
. For example
val createExpensiveGraph: Key => Graph = ... val loader: CacheLoader[Key,Graph] = CacheLoader.from(createExpensiveGraph)
Alternatively the function K => V
can be passed to CacheBuilder directly.
0.7 (copied from Guava-libraries)
Statistics about the performance of a Cache.
Statistics about the performance of a Cache. Instances of this class are immutable.
Cache statistics are incremented according to the following rules:
hitCount
is incremented.missCount
and loadSuccessCount
are
incremented, and the total loading time, in nanoseconds, is added to
totalLoadTime
.missCount
and loadExceptionCount
are incremented, and the total loading time, in nanoseconds, is
added to totalLoadTime
.missCount
.evictionCount
is incremented.Cache#getIfPresent
.A lookup is specifically defined as an invocation of one of the methods
LoadingCache#get(key)
,
Cache#get(key, loader)
, or LoadingCache#getAll(keys)
.
0.7 (copied from Guava-libraries)
An adapter that wraps a Guava-Cache in a Mango-Cache and forwards all method calls to the underlying Guava-Cache.
An adapter that wraps a Guava-Cache in a Mango-Cache and forwards all method calls to the underlying Guava-Cache.
0.7
A semi-persistent mapping from keys to values.
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.
0.7 (copied from Guava-libraries)
An adapter that wraps a Guava-LoadingCache
in a LoadingCache and forwards all
method calls to the underlying Guava-LoadingCache
.
An adapter that wraps a Guava-LoadingCache
in a LoadingCache and forwards all
method calls to the underlying Guava-LoadingCache
.
0.7
The reason why a cached entry was removed.
The reason why a cached entry was removed. See the companion object for the individual RemovalCause cases.
0.7 (copied from guava-libraries)
A notification of the removal of a single entry.
A notification of the removal of a single entry. The key and/or value may be
None
if the corresponding key/value was already garbage collected.
A key/value pair associated with CacheBuilder, this class holds strong references to the key and value, regardless of the type of references the cache may be using.
the key of the cache entry
the value of the cache entry
the cause for which the entry was removed
0.7 (copied from Guava-libraries)
Utility functions to convert between Guava Cache[K, V]
and Cache[K, V]
and vice versa.
Factory for CacheBuilder instances.
Factory for CacheLoader instances.
CacheStats helper functions
Utility functions to convert between Guava LoadingCache[K, V]
and LoadingCache[K, V]
and vice versa.
Available RemovalCauses
A function RemovalNotification[K, V] => Unit
that can receive a notification when an entry is
removed from a cache.
A function RemovalNotification[K, V] => Unit
that can receive a notification when an entry is
removed from a cache. The removal resulting in notification could have occured to an entry being
manually removed or replaced, or due to eviction resulting from timed expiration, exceeding a
maximum size, or garbage collection.
An instance may be called concurrently by multiple threads to process different entries.
Implementations of RemovalListener
should avoid performing blocking calls or synchronizing on
shared resources.
0.7
Calculates the weights of cache entries.
Calculates the weights of cache entries.
0.7
This package contains caching utilities.
The core interface used to represent caches is Cache. In-memory caches can be configured and created using CacheBuilder, with cache entries being loaded by CacheLoader. Statistics about cache performance are exposed using CacheStats.
See the Guava User Guide article on caches.
0.7 (copied from Guava-libraries)