public abstract class CacheLoader<K,V> extends Object implements FunctionalCacheLoader<K,V>
CacheLoader
has
several advantages. The usable features with a loader are explained in the following.
Transparent operation: If configured, the loader is invoked implicitly, in case
there is no value in the cache or it is expired, by the cache methods get()
,
getAll()
or getEntry()
as well as MutableCacheEntry.getValue()
.
The cache loader can be invoked explicitly via {
AdvancedCacheLoader
,
FunctionalCacheLoader
,
AsyncCacheLoader
Constructor and Description |
---|
CacheLoader() |
Modifier and Type | Method and Description |
---|---|
abstract V |
load(K key)
Retrieves or generates data based on the key.
|
Map<K,V> |
loadAll(Iterable<? extends K> keys,
Executor executor)
Loads multiple values to the cache.
|
public abstract V load(K key) throws Exception
From inside this method it is illegal to call methods on the same cache. This may cause a deadlock.
API rationale: This method declares an exception to allow any unhandled exceptions of the loader implementation to just pass through. Since the cache needs to catch an deal with loader exceptions in any way, this saves otherwise necessary try/catch clauses in the loader.
load
in interface FunctionalCacheLoader<K,V>
key
- the non-null key to provide the value for.null
values a NullPointerException
is thrown, but the expiry policy is
called before it.Exception
- Unhandled exception from the loader. Exceptions are suppressed or
wrapped and rethrown via a CacheLoaderException
load(Object)
public Map<K,V> loadAll(Iterable<? extends K> keys, Executor executor) throws Exception
From inside this method it is illegal to call methods on the same cache. This may cause a deadlock.
The method is provided to complete the API. At the moment cache2k is not using it. Please see the road map.
keys
- set of keys for the values to be loadedexecutor
- an executor for concurrent loadingnull
if the cache permits
null
values.Exception
- Unhandled exception from the loader. Exceptions are suppressed or
wrapped and rethrown via a CacheLoaderException
.
If an exception happens the cache may retry the load with the
single value load method.cache2k API documentation. Copyright © 2000–2020 headissue GmbH, Munich.