public class HazelcastAsyncHybridCache<K,V> extends ManagedHybridCacheSupport implements Cache<K,V>
ManagedCache and Cache that does not require the values to be Serializable.
It works by caching values locally and broadcasting invalidations cluster-wide using a Hazelcast ITopic.
Cache entries are invalidated when the cache is modified through one of the methods clear(), remove(K),
replace(K, V, V), or put(K, V) (when it overwrites an existing value).
cacheManager, name| Constructor and Description |
|---|
HazelcastAsyncHybridCache(String name,
CacheFactory localCacheFactory,
com.hazelcast.core.ITopic<K> invalidationTopic,
CacheLoader<K,V> cacheLoader,
HazelcastCacheManager cacheManager,
CacheSettings settings) |
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(CacheEntryListener<K,V> listener,
boolean includeValues)
Adds a
CacheEntryListener |
void |
clear()
Clear the cache.
|
boolean |
containsKey(K key)
Returns whether an entry exists in the cache under the specified key.
|
V |
get(K key)
Retrieve an object from this cache.
|
V |
get(K key,
Supplier<? extends V> valueSupplier)
Retrieve an object from this cache.
|
Collection<K> |
getKeys()
Gets the keys of all objects currently stored in the cache.
|
protected ManagedCache |
getLocalCache() |
String |
getName()
The name of the cache, uniquely identifies this cache.
|
boolean |
isFlushable()
Returns true if this cache can be safely flushed any time.
|
boolean |
isReplicateAsynchronously() |
void |
put(K key,
V value)
Put an object into the cache.
|
V |
putIfAbsent(K key,
V value)
Atomically associates the specified key with the given value if it is not already associated with a value.
|
void |
remove(K key)
Remove the object identified by the key from the cache.
|
boolean |
remove(K key,
V value)
Atomically removes the entry for a key only if currently mapped to a given value.
|
void |
removeAll()
Remove all of the objects from this cache.
|
void |
removeListener(CacheEntryListener<K,V> listener)
Removes a
CacheEntryListener |
boolean |
replace(K key,
V oldValue,
V newValue)
Atomically replaces the entry for a key only if currently mapped to a given value.
|
currentExpireAfterAccessMillis, currentExpireAfterWriteMillis, currentMaxEntries, getStatistics, isLocal, isReplicateViaCopy, isStatisticsEnabled, setStatistics, updateExpireAfterAccess, updateExpireAfterWrite, updateMaxEntriesclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetCacheCollectorpublic HazelcastAsyncHybridCache(String name, CacheFactory localCacheFactory, com.hazelcast.core.ITopic<K> invalidationTopic, CacheLoader<K,V> cacheLoader, HazelcastCacheManager cacheManager, CacheSettings settings)
public void clear()
ManagedCacheclear in interface ManagedCachepublic boolean containsKey(@Nonnull K key)
CacheNote that:
CacheLoader,
it will not be called. Obviously, any call to Cache.get(Object)
will call the corresponding CacheLoader (if required).CacheSettings.getReplicateViaCopy()
set to false and CacheSettings.getLocal() set to false,
then only the local copy of the cache is checked. A local cache on
another node may contain an entry under the specified key.containsKey in interface Cache<K,V>key - the key for the entry to check for containmentpublic V get(@Nonnull K key)
Cache@Nonnull public V get(@Nonnull K key, @Nonnull Supplier<? extends V> valueSupplier)
Cache
If no value is present in the cache, the valueSupplier will be used to populate the entry and be counted
as a cache miss.
get in interface Cache<K,V>key - the key uniquely identifying the object to be retrievedvalueSupplier - the supplier to call if no value is stored in the cache. the value supplied by the supplier
cannot be null@Nonnull public Collection<K> getKeys()
Cache@Nonnull public String getName()
ManagedCachegetName in interface Cache<K,V>getName in interface ManagedCachegetName in class ManagedHybridCacheSupportpublic boolean isFlushable()
ManagedCache
This method is used by CacheManager.flushCaches() to only flush caches that can be safely flushed. ManagedCache.clear() ignores this value.
isFlushable in interface ManagedCachepublic boolean isReplicateAsynchronously()
isReplicateAsynchronously in interface ManagedCachepublic void put(@Nonnull K key, @Nonnull V value)
Cache
NOTE: This method should not be used on hybrid
caches that maintain consistency only by invalidating the key on other cluster nodes. Instead, such hybrid
caches should use CacheLoader semantics and supply a CacheLoader when getting the Cache.
public V putIfAbsent(@Nonnull K key, @Nonnull V value)
Cache
NOTE: This method should not be used on hybrid
caches that maintain consistency only by invalidating the key on other cluster nodes. Instead, such hybrid
caches should use CacheLoader semantics and supply a CacheLoader when getting the Cache.
putIfAbsent in interface Cache<K,V>key - the key with which the specified value is associatedvalue - the non-null value to be cachednull if there was no mapping for the keypublic void remove(@Nonnull K key)
Cachepublic boolean remove(@Nonnull K key, @Nonnull V value)
Cachepublic void removeAll()
Cachepublic boolean replace(@Nonnull K key, @Nonnull V oldValue, @Nonnull V newValue)
Cachereplace in interface Cache<K,V>key - the key with which the specified value is associatedoldValue - the value expected to be associated with the specified keynewValue - the value to be associated with the specified keytrue if the value was replaced, false otherwisepublic void addListener(@Nonnull CacheEntryListener<K,V> listener, boolean includeValues)
CacheCacheEntryListeneraddListener in interface Cache<K,V>listener - the listenerincludeValues - if the events sent to this listener will include old/new value. This is can be used
in cases when the cost of finding these values is big (network sync) but the listener is not interested in
the concrete values for events its getting. The support for this parameter is optional and implementation dependantpublic void removeListener(@Nonnull CacheEntryListener<K,V> listener)
CacheCacheEntryListenerremoveListener in interface Cache<K,V>listener - the listenerprotected ManagedCache getLocalCache()
getLocalCache in class ManagedHybridCacheSupportCopyright © 2018 Atlassian. All rights reserved.