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.- Author:
- ben.manes@gmail.com (Ben Manes)
-
Nested Class Summary
Nested classes/interfaces inherited from interface javax.cache.Cache
javax.cache.Cache.Entry<K,V> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final EventDispatcher<K, V> protected final Executorprotected final javax.cache.expiry.ExpiryPolicyprotected final Set<CompletableFuture<?>> protected 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 longvoidderegisterCacheEntryListener(javax.cache.configuration.CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) @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) protected static longnanosToMillis(long nanos) voidvoidbooleanputIfAbsent(K key, V value) 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) booleanbooleanvoidvoidbooleanbooleanprotected final voidChecks that the cache is not closed.protected final voidsetAccessExpirationTime(K key, Expirable<?> expirable, long currentTimeMS) Sets the access expiration time.<T> TMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
cacheLoader
-
inFlight
-
statistics
-
dispatcher
-
expiry
protected final javax.cache.expiry.ExpiryPolicy expiry -
executor
-
ticker
-
-
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
-
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
-
remove
-
remove
-
getAndRemove
-
replace
-
replace
-
getAndReplace
-
removeAll
-
removeAll
-
clear
-
getConfiguration
-
getConfiguration
- Returns:
- the cache's configuration
-
invoke
-
invokeAll
-
getName
-
getCacheManager
-
isClosed
-
close
-
unwrap
-
registerCacheEntryListener
-
deregisterCacheEntryListener
-
iterator
-
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
-