public abstract class EhcacheBase<K,V> extends java.lang.Object implements InternalCache<K,V>
Cache
interface that is common to all Ehcache implementationModifier and Type | Class and Description |
---|---|
protected class |
EhcacheBase.Jsr107CacheBase |
Cache.Entry<K,V>
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<BulkOps,java.util.concurrent.atomic.LongAdder> |
bulkMethodEntries |
protected <any> |
clearObserver |
protected <any> |
conditionalRemoveObserver |
protected <any> |
getAllObserver |
protected <any> |
getObserver |
protected org.slf4j.Logger |
logger |
protected <any> |
putAllObserver |
protected <any> |
putIfAbsentObserver |
protected <any> |
putObserver |
protected <any> |
removeAllObserver |
protected <any> |
removeObserver |
protected <any> |
replaceObserver |
protected ResilienceStrategy<K,V> |
resilienceStrategy |
protected org.ehcache.core.EhcacheRuntimeConfiguration<K,V> |
runtimeConfiguration |
protected org.ehcache.core.StatusTransitioner |
statusTransitioner |
protected Store<K,V> |
store |
Modifier and Type | Method and Description |
---|---|
protected void |
addBulkMethodEntriesCount(BulkOps op,
long count) |
void |
addHook(LifeCycled hook)
Add lifecycle hooks
|
protected static void |
checkNonNull(java.lang.Object... things) |
protected static void |
checkNonNull(java.lang.Object thing) |
protected void |
checkNonNullContent(java.util.Collection<?> collectionOfThings) |
void |
clear()
Removes all mappings currently present in the
Cache . |
void |
close()
Transitions this
UserManagedCache to UNINITIALIZED . |
boolean |
containsKey(K key)
Checks whether a mapping for the given key is present, without retrieving the associated value.
|
protected abstract Store.ValueHolder<V> |
doGet(K key) |
protected abstract java.util.Map<K,V> |
doGetAllInternal(java.util.Set<? extends K> keys,
boolean includeNulls) |
protected abstract Store.PutStatus |
doPut(K key,
V value) |
protected abstract void |
doPutAll(java.util.Map<? extends K,? extends V> entries) |
protected abstract Store.ValueHolder<V> |
doPutIfAbsent(K key,
V value,
java.util.function.Consumer<java.lang.Boolean> put) |
protected abstract Store.RemoveStatus |
doRemove(K key,
V value) |
protected abstract void |
doRemoveAll(java.util.Set<? extends K> keys) |
protected abstract boolean |
doRemoveInternal(K key) |
protected abstract V |
doReplace(K key,
V value) |
protected abstract Store.ReplaceStatus |
doReplace(K key,
V oldValue,
V newValue) |
V |
get(K key)
Retrieves the value currently mapped to the provided key.
|
java.util.Map<K,V> |
getAll(java.util.Set<? extends K> keys)
Retrieves all values associated with the given key set.
|
protected java.util.Map<K,V> |
getAllInternal(java.util.Set<? extends K> keys,
boolean includeNulls) |
java.util.Map<BulkOps,java.util.concurrent.atomic.LongAdder> |
getBulkMethodEntries()
BulkMethodEntries
|
protected V |
getNoLoader(K key) |
CacheRuntimeConfiguration<K,V> |
getRuntimeConfiguration()
Exposes the
CacheRuntimeConfiguration associated with this Cache instance. |
Status |
getStatus()
Returns the current
Status of this UserManagedCache . |
void |
init()
Transitions this
UserManagedCache to AVAILABLE . |
java.util.Iterator<Cache.Entry<K,V>> |
iterator()
Returns an iterator over the cache entries.
|
protected boolean |
newValueAlreadyExpired(K key,
V oldValue,
V newValue) |
protected static <K,V> boolean |
newValueAlreadyExpired(org.slf4j.Logger logger,
ExpiryPolicy<? super K,? super V> expiry,
K key,
V oldValue,
V newValue) |
void |
put(K key,
V value)
Associates the given value to the given key in this
Cache . |
void |
putAll(java.util.Map<? extends K,? extends V> entries)
Associates all the provided key:value pairs.
|
V |
putIfAbsent(K key,
V value)
Maps the specified key to the specified value in this cache, unless a non-expired mapping
already exists.
|
void |
remove(K key)
Removes the value, if any, associated with the provided key.
|
boolean |
remove(K key,
V value)
Removes the entry for a key only if currently mapped to the given value
and the entry is not expired.
|
void |
removeAll(java.util.Set<? extends K> keys)
Removes any associated value for the given key set.
|
protected boolean |
removeInternal(K key) |
V |
replace(K key,
V value)
Replaces the entry for a key only if currently mapped to some value and the entry is not expired.
|
boolean |
replace(K key,
V oldValue,
V newValue)
Replaces the entry for a key only if currently mapped to the given value
and the entry is not expired.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createJsr107Cache, getCacheLoaderWriter
protected final org.slf4j.Logger logger
protected final org.ehcache.core.StatusTransitioner statusTransitioner
protected final ResilienceStrategy<K,V> resilienceStrategy
protected final org.ehcache.core.EhcacheRuntimeConfiguration<K,V> runtimeConfiguration
protected final <any> getObserver
protected final <any> getAllObserver
protected final <any> putObserver
protected final <any> putAllObserver
protected final <any> removeObserver
protected final <any> removeAllObserver
protected final <any> conditionalRemoveObserver
protected final <any> putIfAbsentObserver
protected final <any> replaceObserver
protected final <any> clearObserver
protected final java.util.Map<BulkOps,java.util.concurrent.atomic.LongAdder> bulkMethodEntries
protected abstract Store.ValueHolder<V> doGet(K key) throws StoreAccessException
StoreAccessException
protected abstract Store.PutStatus doPut(K key, V value) throws StoreAccessException
StoreAccessException
public boolean containsKey(K key)
containsKey
in interface Cache<K,V>
key
- the key, may not be null
true
if a mapping is present, false
otherwisepublic void remove(K key) throws CacheWritingException
remove
in interface Cache<K,V>
key
- the key to remove the value for, may not be null
CacheWritingException
- if the CacheLoaderWriter
associated with this cache threw an
Exception
while removing the value for the given key from the underlying system of record.protected boolean removeInternal(K key)
protected abstract boolean doRemoveInternal(K key) throws StoreAccessException
StoreAccessException
public void clear()
Cache
.
It does so without invoking the CacheLoaderWriter
or any registered
CacheEventListener
instances.
This is not an atomic operation and can potentially be very expensive.
public V putIfAbsent(K key, V value)
This is equivalent to
if (!cache.containsKey(key)) cache.put(key, value); return null; else return cache.get(key);except that the action is performed atomically.
The value can be retrieved by calling the get
method
with a key that is equal to the original key.
Neither the key nor the value can be null
.
putIfAbsent
in interface Cache<K,V>
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keynull
if no such mapping existed or the mapping was expiredprotected abstract Store.ValueHolder<V> doPutIfAbsent(K key, V value, java.util.function.Consumer<java.lang.Boolean> put) throws StoreAccessException
StoreAccessException
public java.util.Iterator<Cache.Entry<K,V>> iterator()
Due to the interactions of the cache and iterator contracts it is possible for iteration to return expired entries.
public java.util.Map<K,V> getAll(java.util.Set<? extends K> keys) throws BulkCacheLoadingException
getAll
in interface Cache<K,V>
keys
- keys to query for, may not contain null
null
if the key was not mappedBulkCacheLoadingException
- if loading some or all values failedprotected java.util.Map<K,V> getAllInternal(java.util.Set<? extends K> keys, boolean includeNulls)
protected abstract java.util.Map<K,V> doGetAllInternal(java.util.Set<? extends K> keys, boolean includeNulls) throws StoreAccessException
StoreAccessException
public void putAll(java.util.Map<? extends K,? extends V> entries) throws BulkCacheWritingException
putAll
in interface Cache<K,V>
entries
- key:value pairs to associate, keys or values may not be null
BulkCacheWritingException
- if the CacheLoaderWriter
associated with this cache threw an
Exception
while writing given key:value pairs to the underlying system of record.protected abstract void doPutAll(java.util.Map<? extends K,? extends V> entries) throws StoreAccessException, BulkCacheWritingException
public void removeAll(java.util.Set<? extends K> keys) throws BulkCacheWritingException
removeAll
in interface Cache<K,V>
keys
- keys to remove values for, may not be null
BulkCacheWritingException
- if the CacheLoaderWriter
associated with this cache threw an
Exception
while removing mappings for given keys from the underlying system of record.protected abstract void doRemoveAll(java.util.Set<? extends K> keys) throws BulkCacheWritingException, StoreAccessException
protected static <K,V> boolean newValueAlreadyExpired(org.slf4j.Logger logger, ExpiryPolicy<? super K,? super V> expiry, K key, V oldValue, V newValue)
public boolean remove(K key, V value)
This is equivalent to
if (cache.containsKey(key) && cache.get(key).equals(value)) { cache.remove(key); return true; } else return false;except that the action is performed atomically.
The key cannot be null
.
protected abstract Store.RemoveStatus doRemove(K key, V value) throws StoreAccessException
StoreAccessException
public V replace(K key, V value)
This is equivalent to
V oldValue = cache.get(key); if (oldValue != null) { cache.put(key, value); } return oldValue;except that the action is performed atomically.
Neither the key nor the value can be null
.
protected abstract V doReplace(K key, V value) throws StoreAccessException
StoreAccessException
public boolean replace(K key, V oldValue, V newValue)
This is equivalent to
if (cache.containsKey(key) && cache.get(key).equals(oldValue)) { cache.put(key, newValue); return true; } else return false;except that the action is performed atomically.
Neither the key nor the value can be null
.
replace
in interface Cache<K,V>
key
- key with which the specified value is associatedoldValue
- value expected to be associated with the specified keynewValue
- value to be associated with the specified keyprotected abstract Store.ReplaceStatus doReplace(K key, V oldValue, V newValue) throws StoreAccessException
StoreAccessException
public CacheRuntimeConfiguration<K,V> getRuntimeConfiguration()
CacheRuntimeConfiguration
associated with this Cache instance.getRuntimeConfiguration
in interface Cache<K,V>
public void init()
UserManagedCache
to AVAILABLE
.
If an error occurs before the UserManagedCache
is AVAILABLE
, it will revert to
UNINITIALIZED
and attempt to properly release all resources.
init
in interface UserManagedCache<K,V>
public void close()
UserManagedCache
to UNINITIALIZED
.
This will release all resources held by this cache.
Failure to release a resource will not prevent other resources from being released.
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface UserManagedCache<K,V>
public Status getStatus()
Status
of this UserManagedCache
.getStatus
in interface UserManagedCache<K,V>
Status
public void addHook(LifeCycled hook)
addHook
in interface InternalCache<K,V>
hook
- hook it to lifecycleprotected void addBulkMethodEntriesCount(BulkOps op, long count)
public java.util.Map<BulkOps,java.util.concurrent.atomic.LongAdder> getBulkMethodEntries()
getBulkMethodEntries
in interface InternalCache<K,V>
protected static void checkNonNull(java.lang.Object thing)
protected static void checkNonNull(java.lang.Object... things)
protected void checkNonNullContent(java.util.Collection<?> collectionOfThings)