public class CacheProxy<K,V> extends Object implements Cache<K,V>
Cache backed by a Caffeine cache.Cache.Entry<K,V>| Modifier and Type | Field and Description |
|---|---|
protected Optional<CacheLoader<K,V>> |
cacheLoader |
protected EventDispatcher<K,V> |
dispatcher |
protected Executor |
executor |
protected ExpiryPolicy |
expiry |
protected JCacheStatisticsMXBean |
statistics |
protected Ticker |
ticker |
| Constructor and Description |
|---|
CacheProxy(String name,
Executor executor,
CacheManager cacheManager,
CaffeineConfiguration<K,V> configuration,
Cache<K,Expirable<V>> cache,
EventDispatcher<K,V> dispatcher,
Optional<CacheLoader<K,V>> cacheLoader,
ExpiryPolicy expiry,
Ticker ticker,
JCacheStatisticsMXBean statistics) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
void |
close() |
boolean |
containsKey(K key) |
protected Map<K,V> |
copyMap(Map<K,Expirable<V>> map)
Returns a deep copy of the map if value-based caching is enabled.
|
protected <T> T |
copyOf(T object)
Returns a copy of the value if value-based caching is enabled.
|
protected V |
copyValue(@Nullable Expirable<V> expirable)
Returns a copy of the value if value-based caching is enabled.
|
protected long |
currentTimeMillis() |
void |
deregisterCacheEntryListener(CacheEntryListenerConfiguration<K,V> cacheEntryListenerConfiguration) |
V |
get(K key) |
Map<K,V> |
getAll(Set<? extends K> keys) |
protected Map<K,Expirable<V>> |
getAndFilterExpiredEntries(Set<? extends K> keys,
boolean updateAccessTime)
Returns all of the mappings present, expiring as required, and optionally updates their access
expiry time.
|
V |
getAndPut(K key,
V value) |
V |
getAndRemove(K key) |
V |
getAndReplace(K key,
V value) |
CacheManager |
getCacheManager() |
CaffeineConfiguration<K,V> |
getConfiguration() |
<C extends Configuration<K,V>> |
getConfiguration(Class<C> clazz) |
String |
getName() |
protected long |
getWriteExpireTimeMS(boolean created)
Returns the time when the entry will expire.
|
<T> T |
invoke(K key,
EntryProcessor<K,V,T> entryProcessor,
Object... arguments) |
<T> Map<K,EntryProcessorResult<T>> |
invokeAll(Set<? extends K> keys,
EntryProcessor<K,V,T> entryProcessor,
Object... arguments) |
boolean |
isClosed() |
Iterator<Cache.Entry<K,V>> |
iterator() |
void |
loadAll(Set<? extends K> keys,
boolean replaceExistingValues,
CompletionListener completionListener) |
protected static long |
nanosToMillis(long nanos) |
void |
put(K key,
V value) |
void |
putAll(Map<? extends K,? extends V> map) |
boolean |
putIfAbsent(K key,
V value) |
protected V |
putNoCopyOrAwait(K key,
V value,
boolean publishToWriter,
int[] puts)
Associates the specified value with the specified key in the cache.
|
void |
registerCacheEntryListener(CacheEntryListenerConfiguration<K,V> cacheEntryListenerConfiguration) |
boolean |
remove(K key) |
boolean |
remove(K key,
V oldValue) |
void |
removeAll() |
void |
removeAll(Set<? extends K> keys) |
boolean |
replace(K key,
V value) |
boolean |
replace(K key,
V oldValue,
V newValue) |
protected void |
requireNotClosed()
Checks that the cache is not closed.
|
protected void |
setAccessExpirationTime(K key,
Expirable<?> expirable,
long currentTimeMS)
Sets the access expiration time.
|
<T> T |
unwrap(Class<T> clazz) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorprotected final Optional<CacheLoader<K,V>> cacheLoader
protected final JCacheStatisticsMXBean statistics
protected final EventDispatcher<K,V> dispatcher
protected final ExpiryPolicy expiry
protected final Executor executor
protected final Ticker ticker
public CacheProxy(String name, Executor executor, CacheManager cacheManager, CaffeineConfiguration<K,V> configuration, Cache<K,Expirable<V>> cache, EventDispatcher<K,V> dispatcher, Optional<CacheLoader<K,V>> cacheLoader, ExpiryPolicy expiry, Ticker ticker, JCacheStatisticsMXBean statistics)
public boolean containsKey(K key)
containsKey in interface Cache<K,V>protected Map<K,Expirable<V>> getAndFilterExpiredEntries(Set<? extends K> keys, boolean updateAccessTime)
public void loadAll(Set<? extends K> keys, boolean replaceExistingValues, CompletionListener completionListener)
protected V putNoCopyOrAwait(K key, V value, boolean publishToWriter, int[] puts)
key - key with which the specified value is to be associatedvalue - value to be associated with the specified keypublishToWriter - if the writer should be notifiedputs - the accumulator for additions and updatespublic boolean putIfAbsent(K key, V value)
putIfAbsent in interface Cache<K,V>public V getAndReplace(K key, V value)
getAndReplace in interface Cache<K,V>public <C extends Configuration<K,V>> C getConfiguration(Class<C> clazz)
getConfiguration in interface Cache<K,V>public CaffeineConfiguration<K,V> getConfiguration()
public <T> T invoke(K key, EntryProcessor<K,V,T> entryProcessor, Object... arguments)
public <T> Map<K,EntryProcessorResult<T>> invokeAll(Set<? extends K> keys, EntryProcessor<K,V,T> entryProcessor, Object... arguments)
public CacheManager getCacheManager()
getCacheManager in interface Cache<K,V>public void close()
public void registerCacheEntryListener(CacheEntryListenerConfiguration<K,V> cacheEntryListenerConfiguration)
registerCacheEntryListener in interface Cache<K,V>public void deregisterCacheEntryListener(CacheEntryListenerConfiguration<K,V> cacheEntryListenerConfiguration)
deregisterCacheEntryListener in interface Cache<K,V>public Iterator<Cache.Entry<K,V>> iterator()
protected final void requireNotClosed()
protected final <T> T copyOf(T object)
T - the type of object being copiedobject - the object to be copiedprotected final V copyValue(@Nullable Expirable<V> expirable)
expirable - the expirable value to be copiedprotected final Map<K,V> copyMap(Map<K,Expirable<V>> map)
map - the mapping of keys to expirable valuesprotected final long currentTimeMillis()
protected static long nanosToMillis(long nanos)
protected final void setAccessExpirationTime(K key, Expirable<?> expirable, long currentTimeMS)
key - the entry's keyexpirable - the entry that was operated oncurrentTimeMS - the current time, or 0 if not read yetprotected final long getWriteExpireTimeMS(boolean created)
created - if the write is an insert or update