|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.atlassian.cache.hazelcast.ManagedHybridCacheSupport
com.atlassian.cache.hazelcast.HazelcastHybridCache<K,V>
public class HazelcastHybridCache<K,V>
Implementation of ManagedCache and Cache that can be used when the cached values do not implement
Serializable but cache invalidation must work cluster-wide.
IMap, but stores the actual values in a local
cache. Caches entries are invalidated when the cache is modified through one of the put, clear,
remove or replace methods. Cache entries are never invalidated when get(Object) is called,
not even when a value is lazily created and added to the cache.
These semantics mean that hybrid caches should only be used as computing caches (by providing a CacheLoader) and that values should not be manually put(Object, Object) in the cache.
Doing so will lead to frequent cache evictions.
| Field Summary |
|---|
| Fields inherited from class com.atlassian.cache.hazelcast.ManagedHybridCacheSupport |
|---|
flushable, name |
| Constructor Summary | |
|---|---|
HazelcastHybridCache(String name,
CacheFactory localCacheFactory,
com.hazelcast.core.IMap<K,Long> versionMap,
com.hazelcast.config.MapConfig config,
CacheLoader<K,V> cacheLoader,
CacheSettings settings)
|
|
| Method Summary | |
|---|---|
void |
addListener(CacheEntryListener<K,V> listener,
boolean includeValues)
Adds a CacheEntryListener |
void |
clear()
Clear the cache. |
boolean |
containsKey(K k)
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 |
getManagedCache()
|
String |
getName()
The name of the cache, uniquely identifies this cache. |
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. |
boolean |
updateExpireAfterAccess(long expireAfter,
TimeUnit timeUnit)
Attempts to update the hint regarding how long entries that should be held in the cache, after last access. |
boolean |
updateExpireAfterWrite(long expireAfter,
TimeUnit timeUnit)
Attempts to update the hint regarding how long entries that should be held in the cache, after last write. |
boolean |
updateMaxEntries(int newValue)
Attempts to update the hint regarding the maximum number of entries that should be cached at any time. |
| Methods inherited from class com.atlassian.cache.hazelcast.ManagedHybridCacheSupport |
|---|
currentExpireAfterAccessMillis, currentExpireAfterWriteMillis, currentMaxEntries, getStatistics, isFlushable, isLocal, isReplicateAsynchronously, isReplicateViaCopy |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public HazelcastHybridCache(String name,
CacheFactory localCacheFactory,
com.hazelcast.core.IMap<K,Long> versionMap,
com.hazelcast.config.MapConfig config,
CacheLoader<K,V> cacheLoader,
CacheSettings settings)
| Method Detail |
|---|
public void clear()
ManagedCache
clear in interface ManagedCache
public boolean containsKey(@Nonnull
K k)
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>k - the key for the entry to check for containment
public V get(@Nonnull
K key)
Cache
get in interface Cache<K,V>key - the key uniquely identifying the object to be retrieved
null if the object is not found
@Nonnull
public V get(@Nonnull
K key,
@Nonnull
Supplier<? extends V> valueSupplier)
CachevalueSupplier 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
getKeys in interface Cache<K,V>Objects keys@Nonnull public String getName()
ManagedCache
getName in interface Cache<K,V>getName in interface ManagedCachegetName in class ManagedHybridCacheSupport
public void put(@Nonnull
K key,
@Nonnull
V value)
Cache
NOTE: Users of caches that wish to be well behaved in a clustered environment should use the
CacheLoader semantics and supply a CacheLoader when getting the Cache.
put in interface Cache<K,V>key - the key uniquely identifying the object to be added into the cachevalue - the non-null value to be cached
public V putIfAbsent(@Nonnull
K key,
@Nonnull
V value)
putIfAbsent in interface Cache<K,V>key - the key with which the specified value is associatedvalue - the non-null value to be cached
null if there was no mapping for the key
public void remove(@Nonnull
K key)
Cache
remove in interface Cache<K,V>key - the key that uniquely identifies the object to be removed
public boolean remove(@Nonnull
K key,
@Nonnull
V value)
Cache
remove in interface Cache<K,V>key - the key with which the specified value is associatedvalue - the value expected to be associated with the specified key
true if the value was removed, false otherwisepublic void removeAll()
Cache
removeAll in interface Cache<K,V>
public boolean replace(@Nonnull
K key,
@Nonnull
V oldValue,
@Nonnull
V newValue)
Cache
replace 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 key
true if the value was replaced, false otherwise
public boolean updateExpireAfterAccess(long expireAfter,
@Nonnull
TimeUnit timeUnit)
ManagedCache
updateExpireAfterAccess in interface ManagedCacheupdateExpireAfterAccess in class ManagedHybridCacheSupportexpireAfter - Time to retain entries for since their last access.timeUnit - The TimeUnit for the time
public boolean updateExpireAfterWrite(long expireAfter,
@Nonnull
TimeUnit timeUnit)
ManagedCache
updateExpireAfterWrite in interface ManagedCacheupdateExpireAfterWrite in class ManagedHybridCacheSupportexpireAfter - Time to retain entries for since their last write.timeUnit - The TimeUnit for the time
public boolean updateMaxEntries(int newValue)
ManagedCache
updateMaxEntries in interface ManagedCacheupdateMaxEntries in class ManagedHybridCacheSupportnewValue - the new hint value
public void addListener(@Nonnull
CacheEntryListener<K,V> listener,
boolean includeValues)
CacheCacheEntryListener
addListener 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 dependant
public void removeListener(@Nonnull
CacheEntryListener<K,V> listener)
CacheCacheEntryListener
removeListener in interface Cache<K,V>listener - the listenerprotected ManagedCache getManagedCache()
getManagedCache in class ManagedHybridCacheSupport
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||