Class JCacheLoaderAdapter<K,V>
- java.lang.Object
-
- com.github.benmanes.caffeine.jcache.integration.JCacheLoaderAdapter<K,V>
-
- All Implemented Interfaces:
AsyncCacheLoader<K,Expirable<V>>,CacheLoader<K,Expirable<V>>
public final class JCacheLoaderAdapter<K,V> extends java.lang.Object implements CacheLoader<K,Expirable<V>>
An adapter from a JCache cache loader to Caffeine's.
-
-
Field Summary
Fields Modifier and Type Field Description private CacheProxy<K,V>cacheprivate javax.cache.integration.CacheLoader<K,V>delegateprivate EventDispatcher<K,V>dispatcherprivate javax.cache.expiry.ExpiryPolicyexpiryprivate JCacheStatisticsMXBeanstatisticsprivate Tickerticker
-
Constructor Summary
Constructors Constructor Description JCacheLoaderAdapter(javax.cache.integration.CacheLoader<K,V> delegate, EventDispatcher<K,V> dispatcher, javax.cache.expiry.ExpiryPolicy expiry, Ticker ticker, JCacheStatisticsMXBean statistics)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private longexpireTimeMS()@Nullable Expirable<V>load(K key)Computes or retrieves the value corresponding tokey.java.util.Map<K,Expirable<V>>loadAll(java.lang.Iterable<? extends K> keys)Computes or retrieves the values corresponding tokeys.voidsetCache(CacheProxy<K,V> cache)Sets the cache instance that was created with this loader.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.github.benmanes.caffeine.cache.CacheLoader
asyncLoad, asyncLoadAll, asyncReload, reload
-
-
-
-
Field Detail
-
statistics
private final JCacheStatisticsMXBean statistics
-
dispatcher
private final EventDispatcher<K,V> dispatcher
-
expiry
private final javax.cache.expiry.ExpiryPolicy expiry
-
ticker
private final Ticker ticker
-
cache
private CacheProxy<K,V> cache
-
-
Constructor Detail
-
JCacheLoaderAdapter
public JCacheLoaderAdapter(javax.cache.integration.CacheLoader<K,V> delegate, EventDispatcher<K,V> dispatcher, javax.cache.expiry.ExpiryPolicy expiry, Ticker ticker, JCacheStatisticsMXBean statistics)
-
-
Method Detail
-
setCache
public void setCache(CacheProxy<K,V> cache)
Sets the cache instance that was created with this loader.- Parameters:
cache- the cache that uses this loader
-
load
public @Nullable Expirable<V> load(K key)
Description copied from interface:CacheLoaderComputes or retrieves the value corresponding tokey.Warning: loading must not attempt to update any mappings of this cache directly.
- Specified by:
loadin interfaceCacheLoader<K,V>- Parameters:
key- the non-null key whose value should be loaded- Returns:
- the value associated with
keyornullif not found
-
loadAll
public java.util.Map<K,Expirable<V>> loadAll(java.lang.Iterable<? extends K> keys)
Description copied from interface:CacheLoaderComputes or retrieves the values corresponding tokeys. This method is called byLoadingCache.getAll(java.lang.Iterable<? extends K>).If the returned map doesn't contain all requested
keysthen the entries it does contain will be cached andgetAllwill return the partial results. If the returned map contains extra keys not present inkeysthen all returned entries will be cached, but only the entries forkeyswill be returned fromgetAll.This method should be overridden when bulk retrieval is significantly more efficient than many individual lookups. Note that
LoadingCache.getAll(java.lang.Iterable<? extends K>)will defer to individual calls toLoadingCache.get(K)if this method is not overridden.Warning: loading must not attempt to update any mappings of this cache directly.
- Specified by:
loadAllin interfaceCacheLoader<K,V>- Parameters:
keys- the unique, non-null keys whose values should be loaded- Returns:
- a map from each key in
keysto the value associated with that key; may not contain null values
-
expireTimeMS
private long expireTimeMS()
-
-