Class CacheProxy<K,V>
java.lang.Object
com.github.benmanes.caffeine.jcache.CacheProxy<K,V>
- All Implemented Interfaces:
Closeable, AutoCloseable, Iterable<javax.cache.Cache.Entry<K,V>>, javax.cache.Cache<K, V>
- Direct Known Subclasses:
LoadingCacheProxy
An implementation of JSR-107
Cache backed by a Caffeine cache.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) final classAn iterator to safely expose the cache entries.(package private) static enumNested classes/interfaces inherited from interface javax.cache.Cache
javax.cache.Cache.Entry<K,V> -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final javax.cache.CacheManager(package private) final JCacheMXBean(package private) boolean(package private) final CaffeineConfiguration<K, V> (package private) final Copierprotected final EventDispatcher<K, V> protected final Executorprotected final javax.cache.expiry.ExpiryPolicyprotected final Set<CompletableFuture<?>> private static final Logger(package private) final Stringprotected final JCacheStatisticsMXBeanprotected final Ticker -
Constructor Summary
ConstructorsConstructorDescriptionCacheProxy(String name, Executor executor, javax.cache.CacheManager cacheManager, CaffeineConfiguration<K, V> configuration, Cache<K, Expirable<V>> cache, EventDispatcher<K, V> dispatcher, Optional<javax.cache.integration.CacheLoader<K, V>> cacheLoader, javax.cache.expiry.ExpiryPolicy expiry, Ticker ticker, JCacheStatisticsMXBean statistics) -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()voidclose()booleancontainsKey(K key) Returns a deep copy of the map if value-based caching is enabled.protected final <T> @NonNull TcopyOf(@Nullable T object) Returns a copy of the value if value-based caching is enabled.protected final @Nullable VReturns a copy of the value if value-based caching is enabled.protected final longprivate @Nullable javax.cache.integration.CacheWriterExceptiondeleteAllToCacheWriter(Set<? extends K> keys) Deletes all of the entries using the cache writer, retaining only the keys that succeeded.voidderegisterCacheEntryListener(javax.cache.configuration.CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) (package private) voidenableManagement(boolean enabled) Enables or disables the configuration management JMX bean.(package private) voidenableStatistics(boolean enabled) Enables or disables the statistics JMX bean.@Nullable VgetAndFilterExpiredEntries(Set<? extends K> keys, boolean updateAccessTime) Returns all of the mappings present, expiring as required, and optionally updates their access expiry time.@Nullable VgetAndRemove(K key) getAndReplace(K key, V value) javax.cache.CacheManagergetConfiguration(Class<C> clazz) getName()protected final longgetWriteExpireTimeMS(boolean created) Returns the time when the entry will expire.<T> @Nullable TinvokeAll(Set<? extends K> keys, javax.cache.processor.EntryProcessor<K, V, T> entryProcessor, Object... arguments) booleanisClosed()iterator()voidloadAll(Set<? extends K> keys, boolean replaceExistingValues, javax.cache.integration.CompletionListener completionListener) private voidloadAllAndKeepExisting(Set<? extends K> keys) Performs the bulk load where the existing entries are retained.private voidloadAllAndReplaceExisting(Set<? extends K> keys) Performs the bulk load where the existing entries are replace.protected static longnanosToMillis(long nanos) postProcess(Expirable<V> expirable, EntryProcessorEntry<K, V> entry, long currentTimeMS) Returns the updated expirable value after performing the post processing actions.private <T> voidpublishToCacheWriter(Consumer<T> action, Supplier<T> data) Performs the action with the cache writer if write-through is enabled.voidvoidbooleanputIfAbsent(K key, V value) private booleanputIfAbsentNoAwait(K key, V value, boolean publishToWriter) Associates the specified value with the specified key in the cache if there is no existing mapping.protected VputNoCopyOrAwait(K key, V value, boolean publishToWriter, int[] puts) Associates the specified value with the specified key in the cache.voidregisterCacheEntryListener(javax.cache.configuration.CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) booleanbooleanvoidvoidprivate VremoveNoCopyOrAwait(K key) Removes the mapping from the cache without store-by-value copying nor waiting for synchronous listeners to complete.booleanbooleanprivate VreplaceNoCopyOrAwait(K key, V value) Replaces the entry for the specified key only if it is currently mapped to some value.protected final voidChecks that the cache is not closed.protected final voidsetAccessExpirationTime(K key, Expirable<?> expirable, long currentTimeMS) Sets the access expiration time.private @Nullable Throwableprivate static @Nullable ThrowableAttempts to close the resource.<T> Tprivate @Nullable javax.cache.integration.CacheWriterExceptionwriteAllToCacheWriter(Map<? extends K, ? extends V> map) Writes all of the entries to the cache writer if write-through is enabled.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
logger
-
cache
-
configuration
-
cacheManager
final javax.cache.CacheManager cacheManager -
writer
-
cacheMXBean
-
copier
-
name
-
cacheLoader
-
inFlight
-
statistics
-
dispatcher
-
expiry
protected final javax.cache.expiry.ExpiryPolicy expiry -
executor
-
ticker
-
closed
volatile boolean closed
-
-
Constructor Details
-
CacheProxy
public CacheProxy(String name, Executor executor, javax.cache.CacheManager cacheManager, CaffeineConfiguration<K, V> configuration, Cache<K, Expirable<V>> cache, EventDispatcher<K, V> dispatcher, Optional<javax.cache.integration.CacheLoader<K, V>> cacheLoader, javax.cache.expiry.ExpiryPolicy expiry, Ticker ticker, JCacheStatisticsMXBean statistics)
-
-
Method Details
-
containsKey
-
get
-
getAll
-
getAndFilterExpiredEntries
-
loadAll
-
loadAllAndReplaceExisting
-
loadAllAndKeepExisting
-
put
-
getAndPut
-
putNoCopyOrAwait
Associates the specified value with the specified key in the cache.- Parameters:
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 updates- Returns:
- the old value
-
putAll
-
putIfAbsent
-
putIfAbsentNoAwait
Associates the specified value with the specified key in the cache if there is no existing mapping.- Parameters:
key- key with which the specified value is to be associatedvalue- value to be associated with the specified keypublishToWriter- if the writer should be notified- Returns:
- if the mapping was successful
-
remove
-
removeNoCopyOrAwait
-
remove
-
getAndRemove
-
replace
-
replace
-
getAndReplace
-
replaceNoCopyOrAwait
Replaces the entry for the specified key only if it is currently mapped to some value. The entry is not store-by-value copied nor does the method wait for synchronous listeners to complete.- Parameters:
key- key with which the specified value is associatedvalue- value to be associated with the specified key- Returns:
- the old value
-
removeAll
-
removeAll
-
clear
-
getConfiguration
-
getConfiguration
- Returns:
- the cache's configuration
-
invoke
-
postProcess
-
invokeAll
-
getName
-
getCacheManager
-
isClosed
-
close
-
shutdownExecutor
-
tryClose
Attempts to close the resource. If an error occurs and an outermost exception is set, then adds the error to the suppression list.- Parameters:
o- the resource to close if Closeableouter- the outermost error, or null if unset- Returns:
- the outermost error, or null if unset and successful
-
unwrap
-
registerCacheEntryListener
-
deregisterCacheEntryListener
-
iterator
-
enableManagement
void enableManagement(boolean enabled) Enables or disables the configuration management JMX bean. -
enableStatistics
void enableStatistics(boolean enabled) Enables or disables the statistics JMX bean. -
publishToCacheWriter
-
writeAllToCacheWriter
-
deleteAllToCacheWriter
-
requireNotClosed
protected final void requireNotClosed()Checks that the cache is not closed. -
copyOf
protected final <T> @NonNull T copyOf(@Nullable T object) Returns a copy of the value if value-based caching is enabled.- Type Parameters:
T- the type of object being copied- Parameters:
object- the object to be copied- Returns:
- a copy of the object if storing by value or the same instance if by reference
-
copyValue
-
copyMap
-
currentTimeMillis
protected final long currentTimeMillis()- Returns:
- the current time in milliseconds
-
nanosToMillis
protected static long nanosToMillis(long nanos) - Returns:
- the nanosecond time in milliseconds
-
setAccessExpirationTime
-
getWriteExpireTimeMS
protected final long getWriteExpireTimeMS(boolean created) Returns the time when the entry will expire.- Parameters:
created- if the write is an insert or update- Returns:
- the time when the entry will expire, zero if it should expire immediately, Long.MIN_VALUE if it should not be changed, or Long.MAX_VALUE if eternal
-